On 06/23/2020 09:01 AM, PEP 622 wrote:
from enum import Enum
class Color(Enum):
BLACK = 1
RED = 2
BLACK = 1
RED = 2
match color:
case .BLACK | Color.BLACK:
print("Black suits every color")
case BLACK: # This will just assign a new value to BLACK.
...
As others have noted, the leading dot to disambiguate between a name assignment
and a value check is going to be a problem. I think it's also unnecessary
because instead of
case BLACK:
blahblah()
we can do
case _:
# look ma! BLACK is just "color"!
BLACK = color # if you really want it bound to another name
In other words, the PEP is currently building in two ways to do the same thing -- make a
default case. One of those ways is going to be a pain; the other, once renamed to
"else", will be perfect! :-) As a bonus, no special casing for leading dots.
--
~Ethan~
_______________________________________________
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/CMA3U3CBIPONZPSPXWFCDZWNUZKIESPH/
Code of Conduct: http://python.org/psf/codeofconduct/