El mar., 23 jun. 2020 a las 9:10, Guido van Rossum (<email@example.com
I'm happy to present a new PEP for the python-dev community to review. This is joint work with Brandt Bucher, Tobias Kohn, Ivan Levkivskyi and Talin.
Thanks to Guido and all the others working on this! It's going to be a great addition to the language.
One piece of bikeshedding: I agree with the previous posters who said that the ".x" syntax for referring to variables isn't great, and I'd prefer marking variables that are being assigned to with a special symbol. So instead of:
y = 3
case Point(x, .y): ... # x is assigned to, y is looked up
y = 3
case Point($x, y): ... # x is assigned to, y is looked up
The trouble with the current syntax is that if you forget the ".", you always get a hard-to-detect bug: your pattern unexpectedly matches and "y" suddenly has a different value. Even if you find the bug, it's hard to find out where exactly the mistake happened.
But with the proposed "$" syntax, if you forget the "$", you probably will just immediately get a NameError that will tell you exactly where your bug is. (Except of course if you happen to already have the name "x" in scope, but that's hopefully not very common, and it's already what happens if you typo a local variable name.)