> From: Baptiste Carvello <devel2...@baptiste-carvello.net>
> Subject: [Python-Dev] Re: PEP 622 constant value syntax idea
> 
> What about simply "is", which is already a keyword?
> 
> AFAIK "is" has no meaning as a prefix operator as of now, so hopefully
> it would not make the grammar ambiguous (how can one check that for sure?).
> 
> match color:
>    case is RED:
>        print("red")
>    case is BLUE:
>        print("blue")
>    case other:
>        print(f"unknown color {other}")
> 
> or with Rhodri James' example:
> 
> match value:
>    case is x:
>        print("value matches")
>    case Point(is x, y):
>        print("value matches x, y captured")
>    case Line(Point(is x1, y1), Point(x2, is y2)):
>        print("wouldn't call that pretty, but not ugly either")
> 
> 
> Cheers,
> Baptiste
> 
> P.S.: granted, it could mislead some users into thinking that the
> comparison is done with "is" instead of "=="; but then, patterns are
> special in many ways, users will have to just learn them…

That is exactly why I think you should make the special things special and keep 
the familiar things as you know them.
So constants and variables like they are in other uses and matched 
values/patterns using a special construction/syntax.

And we don’t need the catch all case if we would have the IMHO more familiar:

match Color(…) as color:
   case RED:
       print(f”{color} is red")
   case BLUE:
       print(f”{color} is blue”)
   else:
       print(f"unknown color {color}”)

thus eliminating the whole ‘case <var>’ issue.
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/4NTH5H6RX2KTVVJFJUF53UWESJIBCLYS/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to