On Thu, Nov 12, 2020 at 09:40:02PM +0300, Paul Sokolovsky wrote:
> match foo: > case ("foo", >val1): > ... > case ("bar", >val2): > ... > 1. Much more intuitive for beginners. (If Python adopts it, I see > other "user-friendly" languages adopting the same pattern in the > coming decades). I think you and I have a very different concept of "intuitive for beginners" here. I don't think that using the *greater than symbol* as a sigil for assignment would have been "intuitive" to me as a beginner, or anyone I have helped teach over the years. To me, that statement clearly and obviously could only mean one possible thing: * match a two-sequence where the first item equals "foo" and the second is greater than `val1`; (and similarly for the second case statement). Are there any other languages that use `>` as a prefix sigil to indicate assignment? If we were to use a sigil to represent binding, surely `=` would make more sense than `>`. > 2. Upholds the rights of people who see "match" as glorified "switch" > statement, There is no right for people to dictate that syntax must support their misapprehensions about language features. Or for that matter, no right to dictate *anything* about syntax. There is no universal human right to dictate Python syntax. The best you have is the privilege to attempt to persuade others to support your preference, and for the Steering Council to be swayed by your arguments and/or the popular support for your preference. > and not keen on it doing assignments behind their backs. (The > topic which was recently mentioned on the list.) How is it doing assignments behind your back? The syntax is clear: a name is a binding pattern. That is as much an explicitly assignment statement as import, for, with...as, def or class. This is an assignment "behind your back": def sneaky_assignment(): global x x = 999 sneaky_assignment() There's nothing in the call to `sneaky_assignment` to hint that it assigns a value to the global `x`. Pattern matching is nothing like that: all binding patterns are explicit, all you need is to get past the misapprehension that pattern matching is a switch statement (it isn't!) and it will be clear as daylight: case 1, x: pass Of course x gets assigned to. It's a binding pattern. import sys Of course sys gets assigned to. It's an import. > 3. Solves discrepancy with cases like: > > # Why is this possible? > obj.foo, obj.bar = val > > # And this is not? > match val: > case obj.foo, obj.bar: I agree with this. I think it is surprising that unqualified names are binding patterns but qualified names are not. That difference gives me pause. But using `>` as an assignment sigil is surely worse than the problem you hope to solve with it. -- Steve _______________________________________________ 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/NRRD2FZYWIOWMQ7KQRAKISIUDNC56OTV/ Code of Conduct: http://python.org/psf/codeofconduct/