On 12/07/2020 02:04, Guido van Rossum wrote:
On Sat, Jul 11, 2020 at 5:58 PM Chris Angelico <ros...@gmail.com <mailto:ros...@gmail.com>> wrote:


    Hang on. Matching happens before assignment, so this should use the
    previous value of x for the matching. At least, that's my
    understanding. If you do something like:

    case Point(x, 2):

    it won't assign x unless the second coordinate is 2, right?


Good catch. That's actually undefined -- we want to let the optimizer have some leeway in how to generate  the best code for matching. See https://www.python.org/dev/peps/pep-0622/#performance-considerations

Currently it doesn't optimize all that much -- it just processes patterns from left to right:
```
>>> match Point(3, 3):
...   case Point(x, 42): pass
...
>>> print(x)
3
>>>
```

If I've understood this correctly, my immediate reaction is one of horror.  I'd assumed that a case that failed to match would have no effect.
Rob Cliffe
_______________________________________________
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/HFYHV6DKX227JT2ZR2UYLVT3N7O4JDCK/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to