On 2020-07-12 01:32, Chris Angelico wrote:
On Sun, Jul 12, 2020 at 10:30 AM Greg Ewing <greg.ew...@canterbury.ac.nz> wrote:

Just had another thought about marking assignment targets.

The PEP currently forbids repeating bound names in a pattern
to avoid raising expectations that

     case Point(x, x):

would match only if the two arguments were equal.

But if assignment targets were marked, we could write this as

     case Point(?x, x):

and it would work as expected.


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?

Presumably the assumption is that it would use a local dict for binding, faling back to the actual dict if necessary for lookup, and then update the actual dict if the match is successful. That way, unsuccessful matches won't pollute the actual dict.
_______________________________________________
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/OUT2EZB5VMWT4VGJCGF7DAWMTNJAVHRT/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to