On the other hand I think extending the walrus operator would make the change 
less intrusive and the syntax more easily discoverable:

if match := re.match(r"...", some_string):
    print(match[1], match[2])

if [_, a, b] := re.match(r"...", some_string):
    print(a, b)  # Assuming match objects would then be made into proper 
sequences

Also, since it's not a new operator there's no need to worry about operator 
precedence. And since the current behavior of the walrus operator would already 
implement a subset of the proposed changes, I think it would reduce friction 
when deciding whether or not to adopt it.

One last point is that the new operator would lead to two equivalent constructs:

if thing.value matches foo:
    ...

if foo := thing.value:
    ...

I think using the "matches" operator like this would probably be frowned upon 
but that's yet another thing you would need to explain when teaching the 
language. Also, I can easily imagine some codestyle where the walrus operator 
would be considered obsolete as it would overlap with the "matches" operator 
while only providing a subset of the functionality, thus leading to 
fragmentation in the ecosystem.
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/6YUVCSL23YKSCKRDJXVUZW2XSGXAYCJM/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to