[Python-ideas] Match statement brainstorm
Ethan Furman
ethan at stoneleaf.us
Wed May 25 03:38:34 EDT 2016
On 05/24/2016 10:52 PM, Nick Coghlan wrote:
> Using the running demo:
>
> def demo(arg):
> given arg:
> case x, y, *_: # Tuple matching (implicit name binding)
> ...
> case (.x, .y) as p, q: # Attribute matching
> ...
> case (["x"], ["y"]) as p, q: # Item matching
> ...
> case (.x) as p and isinstance(p, int): # Match + condition
> ...
> case if isinstance(arg, int): # Condition only
> ...
> else: # Default
> ...
>
> The other key change there is introducing "as" to the individual cases
> in order to be able to separate the match pattern definition from the
> local name binding.
With this one I have a clue as to what's going on.
--
~Ethan~
More information about the Python-ideas
mailing list