PEP 622 (match statement) playground

If you are interested in learning more about how PEP 622 would work in practice, but don't feel like compiling a Python 3.10 fork from source, here's good news for you. In a hurry? https://mybinder.org/v2/gh/gvanrossum/patma/master?urlpath=lab/tree/playgrou... This will open a Binder instance that runs a Jupyter kernel built from Brandt Bucher's fork of Python 3.10 that includes the match statement. This is a complete implementation of the PEP. (Note that we've already made some design changes in response to feedback, but the basic syntax is still the same. Expect a new draft within a week.) The code for the playground was contributed by Fernando Perez, Matthias Bussonnier and Chris Holdgraf. We also thank the Binder and Jupyter teams for Binder and Jupyter and all the infrastructure that made this playground possible, and we thank gesis.org for hosting. For details, see https://github.com/gvanrossum/patma/tree/master/binder -- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-c...>

On 1 Jul 2020, at 17:58, Guido van Rossum wrote:
If you are interested in learning more about how PEP 622 would work in practice, but don't feel like compiling a Python 3.10 fork from source, here's good news for you.
In a hurry? https://mybinder.org/v2/gh/gvanrossum/patma/master?urlpath=lab/tree/playgrou...
If I change the example code to: --------------------------------------------------- from dataclasses import dataclass @dataclass class Point: x: int y: int z = 42 def whereis(point): w = 23 match point: case Point(0, 0): print("Origin") case Point(0, y): print(f"Y={y}") case Point(x, 0): print(f"X={x}") case Point(): print("Somewhere else") case .w: print("Not the answer") case .z: print("The answer") case z: print("Not a point") --------------------------------------------------- whereis(42) gives me: --------------------------------------------------- UnboundLocalError Traceback (most recent call last) <ipython-input-16-3257cdeaff94> in <module> ----> 1 whereis(42) <ipython-input-13-35ff7b1c0f2f> in whereis(point) 10 def whereis(point): 11 w = 23 12 match point: 13 case Point(0, 0): 14 print("Origin") 15 case Point(0, y): 16 print(f"Y={y}") 17 case Point(x, 0): 18 print(f"X={x}") 19 case Point(): 20 print("Somewhere else") 21 case .w: 22 print("Not the answer") ---> 23 case .z: 24 print("The answer") 25 case z: 26 print("Not a point") UnboundLocalError: local variable 'z' referenced before assignment --------------------------------------------------- This looks strange to me. In all other cases of variable lookup the global variable z would be found. whereis(23) however works.
[...]
Servus, Walter

Walter Dörwald wrote:
This looks strange to me. In all other cases of variable lookup the global variable z would be found.
The next case assigns to z, making z local to whereis. This is consistent with python's existing scoping rules (for example, try rewriting this as the equivalent if-elif chain and you'll get the same error). It sounds like you want to add "global z" to the top of the function definition.
whereis(23) however works.
This branch is hit before the unbound local lookup is attempted.

It's still weird user experience as if you swap case .z and case z you don't get the Unbound error anymore. SO it can work w/o global.

On Thu, 2 Jul 2020 at 09:28, Matthias Bussonnier <bussonniermatthias@gmail.com> wrote:
It's still weird user experience as if you swap case .z and case z you don't get the Unbound error anymore. SO it can work w/o global.
For some value of work: if z comes before .z, the .z branch will never get evaluated, because the binding of z will take precedence, making the .z branch dead code. This is something I would expect linters to pick up on (eventually), or possibly the compiler itself. And if you don't put z first, anything that hits the .z branch will throw the UnboundLocalError. -Rob

On 1 Jul 2020, at 18:54, Brandt Bucher wrote:
Walter Dörwald wrote:
This looks strange to me. In all other cases of variable lookup the global variable z would be found.
The next case assigns to z, making z local to whereis. This is consistent with python's existing scoping rules (for example, try rewriting this as the equivalent if-elif chain and you'll get the same error). It sounds like you want to add "global z" to the top of the function definition.
whereis(23) however works.
This branch is hit before the unbound local lookup is attempted.
OK, understood. However I still find the rule "dotted names are looked up" and "undotted names are matched" surprising and "case .constant" ugly. A way to solve this would be to use "names at the top level are always looked up". With this the constant value pattern: case .name: could be written as: case name: The capture pattern (of which there can only be one anyway) could then be written as: case object(name): instead of case name: Or we could use "matches are always done against a match object", i.e. the code from the example would look like this: from dataclasses import dataclass @dataclass class Point: x: int y: int z = 42 def whereis(point): w = 23 match point as m: case Point(0, 0): print("Origin") case Point(0, m.y): print(f"Y={m.y}") case Point(m.x, 0): print(f"X={m.x}") case Point(): print("Somewhere else") case w: print("Not the answer") case z: print("The answer") case object(z): print(f"{z!r} is not a point") Servus, Walter

+1 Is there a reason, after all, why we should mark constant patterns as special, and not the opposite? On 02/07/2020 19:10, Walter Dörwald wrote:
On 1 Jul 2020, at 18:54, Brandt Bucher wrote:
Walter Dörwald wrote:
This looks strange to me. In all other cases of variable lookup the global variable z would be found.
The next case assigns to z, making z local to whereis. This is consistent with python's existing scoping rules (for example, try rewriting this as the equivalent if-elif chain and you'll get the same error). It sounds like you want to add "global z" to the top of the function definition.
whereis(23) however works.
This branch is hit before the unbound local lookup is attempted.
OK, understood.
However I still find the rule "dotted names are looked up" and "undotted names are matched" surprising and "case .constant" ugly.
A way to solve this would be to use "names at the top level are always looked up".
With this the constant value pattern:
case .name:
could be written as:
case name:
The capture pattern (of which there can only be one anyway) could then be written as:
case object(name):
instead of
case name:
Or we could use "matches are always done against a match object", i.e. the code from the example would look like this:
from dataclasses import dataclass
@dataclass class Point: x: int y: int
z = 42
def whereis(point): w = 23 match point as m: case Point(0, 0): print("Origin") case Point(0, m.y): print(f"Y={m.y}") case Point(m.x, 0): print(f"X={m.x}") case Point(): print("Somewhere else") case w: print("Not the answer") case z: print("The answer") case object(z): print(f"{z!r} is not a point")
Servus, Walter

Whoa! I have an uneasy feeling about this PEP. AFAIK the usual procedure for adding a new feature to Python is: An idea is raised and attracts some support. Someone sufficiently motivated writes a PEP. The PEP is thoroughly discussed. Eventually a consensus (or at least an "agree to differ" stalemate) is reached. The PEP is accepted (if it is). (Then and only then) Someone works on the implementation. etc. However, PEP 622 only seems to have been presented to the Python community only *after* a well-developed (if not finalised) implementation was built. A fait accompli. So there will inevitably be resistance from the developers to accept changes suggested on python-dev. And since the PEP has Guido's authority behind it, I think it is likely that it will eventually be accepted pretty much as it was originally written. This means that most of the discussion we have seen on python-dev (and there has been a lot) will end up being just pissing in the wind. (I don't mean to be vulgar or disrespectful; I just can't think of another phrase that conveys my meaning so well.) And Guido's 2nd email ("PEP 622: Structural Pattern Matching -- followup") already to me (YMMV) reads rather like "OK, you've had your fun, now try not to joggle our elbows too much while we get on with the work". I don't know how many of the decisions made in the PEP are right and how many could be improved (it is of course a subjective question anyway). I do think it's a pity that the Python community did not have the chance to supply feedback earlier down the road (when IMO it would have been taken more seriously). While Guido and the other developers have obviously already put a huge amount of work into this PEP (and by now probably have a significant emotional investment in it), I do hope that they will take the time to consider seriously and on their merits most/all suggested changes, rather than being tempted to rush through the acceptance and implementation of the PEP. Best wishes Rob Cliffe

On Sat, Jul 4, 2020 at 12:48 AM Rob Cliffe via Python-Dev <python-dev@python.org> wrote:
Whoa!
I have an uneasy feeling about this PEP.
AFAIK the usual procedure for adding a new feature to Python is: An idea is raised and attracts some support. Someone sufficiently motivated writes a PEP. The PEP is thoroughly discussed. Eventually a consensus (or at least an "agree to differ" stalemate) is reached. The PEP is accepted (if it is). (Then and only then) Someone works on the implementation. etc.
However, PEP 622 only seems to have been presented to the Python community only *after* a well-developed (if not finalised) implementation was built. A fait accompli.
The PEP is still a draft and has not been accepted. Don't worry, the normal process is still happening :) Having a reference implementation is a HUGE help, because people can play around with it. There's a fork running an interactive playground so you can go right now and get a feel for the way the syntax works. The implementation has *not* been merged into the CPython trunk. It's not a fait accompli - it's a tool to help people evaluate the proposal (and all of the different variants of the proposal as it evolves). Speaking with my PEP Editor hat on, I would be *thrilled* if more proposals came with ready-to-try code. Only a very few have that luxury, and a lot of the debating happens with nothing but theory - people consider what they *think* they'd do, without actually being able to try it out and see if it really does what they expect. Having a reference implementation isn't necessary, of course, but it's definitely a benefit and not a downside. Also, there HAVE been proposals with full reference implementations that have ended up getting rejected; it's not a guarantee that it'll end up getting merged. Hope that lessens your fears a bit :) ChrisA

I would like to thank everyone who responded to me for their civilised and courteous replies. I actually expected to get a lot of slagging off, but was prepared to accept that for what seemed to me at the time to be a legitimate concern. If my fears were unfounded, I am delighted. If I have been unfair to Guido and the other developers (and it seems that I probably have), I apologise. Thank you. FWIW: I am not against the PEP. I do not have a personal axe to grind, in the form of my own pet idea which I want to see incorporated. I don't like the .name syntax (grit on Tim's monitor; does not suggest the meaning). Nor am I keen on "expressions" being interpreted differently after 'case' than elsewhere in Python. But I don't know what syntax (where necessary) to suggest. I'm not keen on special treatment of the '_' variable, and would prefer to be able to use 'else:' after 'match'. Best wishes Rob Cliffe On 03/07/2020 15:56, Chris Angelico wrote:
The PEP is still a draft and has not been accepted. Don't worry, the normal process is still happening :)
Having a reference implementation is a HUGE help, because people can play around with it. There's a fork running an interactive playground so you can go right now and get a feel for the way the syntax works.
The implementation has *not* been merged into the CPython trunk. It's not a fait accompli - it's a tool to help people evaluate the proposal (and all of the different variants of the proposal as it evolves).
Speaking with my PEP Editor hat on, I would be *thrilled* if more proposals came with ready-to-try code. Only a very few have that luxury, and a lot of the debating happens with nothing but theory - people consider what they *think* they'd do, without actually being able to try it out and see if it really does what they expect. Having a reference implementation isn't necessary, of course, but it's definitely a benefit and not a downside. Also, there HAVE been proposals with full reference implementations that have ended up getting rejected; it's not a guarantee that it'll end up getting merged.
Hope that lessens your fears a bit :)
ChrisA _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-leave@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/E5U5Z6RR... Code of Conduct: http://python.org/psf/codeofconduct/

On Tue, 7 Jul 2020 at 15:04, Rob Cliffe via Python-Dev < python-dev@python.org> wrote:
I don't like the .name syntax (grit on Tim's monitor; does not suggest the meaning). [...] But I don't know what syntax (where necessary) to suggest.
+1(000)
I'm not keen on special treatment of the '_' variable, and would prefer to be able to use 'else:' after 'match'.
I used to be in this "camp", however, a (I think valid) point was raised that "else:" is not a (full) alternative. Due to the restriction on repeated names (e.g. Point(x, x) is illegal), if you want to "throw away" intermediate matches, you will have to either have to come up with new names (Point(unused_1, unused_2)) or use the "_" as currently instituted (Point(_, _)) and "else:" does not cover that insofar as I can tell. Would it be possible here to use a syntax/symbol that is illegal instead of _? I think this has been mooted but my favourite (so far) would be "?" so you have "case ?:" and "Point(?, ?)". Would ?name then work instead of ".name" as well? Not sure that makes its use more/less/equal consistent with the previous suggestion. Apologies if this has been discussed, I have followed the thread(s) but I might well have forgotten or missed something!

On 07/07/2020 15:31, Henk-Jaap Wagenaar wrote:
On Tue, 7 Jul 2020 at 15:04, Rob Cliffe via Python-Dev < python-dev@python.org> wrote:
I'm not keen on special treatment of the '_' variable, and would prefer to be able to use 'else:' after 'match'.
I used to be in this "camp", however, a (I think valid) point was raised that "else:" is not a (full) alternative. Due to the restriction on repeated names (e.g. Point(x, x) is illegal), if you want to "throw away" intermediate matches, you will have to either have to come up with new names (Point(unused_1, unused_2)) or use the "_" as currently instituted (Point(_, _)) and "else:" does not cover that insofar as I can tell.
There are two things here, the specialness of "_" and using "else:" as the catch-all clause. I'm not quite convinced about making "_" non-binding, mostly because of the knock-on effects in the PEP for other types of patterns. It seems to breed more special cases, and I can't help but feel that's a bad sign. On the other hand "else:" would have exactly the effect of "case _:", so we're into arguments about there preferably being only one obvious way to do things. I'd maintain that "else:" is obvious :-) -- Rhodri James *-* Kynesim Ltd

On Tue, Jul 7, 2020 at 8:37 AM Rhodri James <rhodri@kynesim.co.uk> wrote:
I'm not quite convinced about making "_" non-binding, mostly because of the knock-on effects in the PEP for other types of patterns. It seems to breed more special cases, and I can't help but feel that's a bad sign.
After spending some time with it in my head and in the actual testbed, it seems like a reasonable compromise. case Point(x,x): being illegal while x,x=(1,2) is perfectly legal is a bit of contention, but grammar also doesn't need to be perfectly consistent in order to learn to speak a language, it just needs to minimize the context-switching. It'd be so simple if we could use case *:, but alas.

On Tue, 7 Jul 2020 at 15:40, Henk-Jaap Wagenaar <wagenaarhenkjaap@gmail.com> wrote:
On Tue, 7 Jul 2020 at 15:04, Rob Cliffe via Python-Dev <python-dev@python.org> wrote:
I don't like the .name syntax (grit on Tim's monitor; does not suggest the meaning). [...] But I don't know what syntax (where necessary) to suggest.
+1(000)
There's been traffic on the PEP repository which suggests that there is a new version of the PEP incoming which responds to these types of concern. I'm not willing to read raw rst diffs, so I haven't checked any of the details. Hopefully the PEP authors intend to post an updated version (preferably with a summary of changes, for people struggling to keep up with the traffic here!) sometime soon. Paul

On Tue, 7 Jul 2020 at 17:09, Paul Moore <p.f.moore@gmail.com> wrote:
On Tue, 7 Jul 2020 at 15:40, Henk-Jaap Wagenaar <wagenaarhenkjaap@gmail.com> wrote:
On Tue, 7 Jul 2020 at 15:04, Rob Cliffe via Python-Dev <
python-dev@python.org> wrote:
I don't like the .name syntax (grit on Tim's monitor; does not suggest the meaning). [...] But I don't know what syntax (where
necessary) to suggest.
+1(000)
There's been traffic on the PEP repository which suggests that there is a new version of the PEP incoming which responds to these types of concern. I'm not willing to read raw rst diffs, so I haven't checked any of the details.
"PEP 622: Ditch leading dots for name loads": this is now an ex-syntax, it is bereft of life (for this, draft, of the PEP, might come back later!): https://github.com/python/peps/commit/f1de4f169d762cbb46fbfe94d2c01839db9b2f... In there, it makes a good point that namespaced constants are good, especially for this kind of thing (you probably want to e.g. match over a bunch of possible constants which you can then put in an enum or some other namespace).

Hello, On Tue, 7 Jul 2020 17:22:28 +0100 Henk-Jaap Wagenaar <wagenaarhenkjaap@gmail.com> wrote: []
I don't like the .name syntax (grit on Tim's monitor; does
[]
"PEP 622: Ditch leading dots for name loads": this is now an ex-syntax, it is bereft of life (for this, draft, of the PEP, might come back later!): https://github.com/python/peps/commit/f1de4f169d762cbb46fbfe94d2c01839db9b2f...
In there, it makes a good point that namespaced constants are good, especially for this kind of thing (you probably want to e.g. match over a bunch of possible constants which you can then put in an enum or some other namespace).
That's probably a nice move, but requiring constants to be extra-namespaced seems like a pretty arbitrary and limiting "rule" either. This touches on the sentiment which I was too shy to share for a long time even on python-ideas, but would like to take a chance to bring up here now: With the advent of Lua 5.4, Python appears to be **the only** of the popular VHLL/scripting languages which doesn't support defining of constants in the core language: JavaScript has "const foo = 1;" PHP has "const foo = 1;" Perl has "use constant foo => 1;" Lua has "local foo <const> = 1" The closest Python has is: --- from typing import Final foo: Final = 1 --- which is done on the level of an arbitrary external module, and doesn't enforce or employ const'ness on the language core level (unlike other languages above). If there were constants on the level of the core language, it would *also* allow to elegantly resolve issue with the usage in match patterns (in addition to baseline benefits of allowing programmers to express programs more clearly and perform low-hanging optimizations). E.g.: --- from __future__ import const FOO: const = 1 match val: case FOO: # obviously matches by constant's value --- -- Best regards, Paul mailto:pmiscml@gmail.com

On 8/07/20 5:30 am, Paul Sokolovsky wrote:
from __future__ import const
FOO: const = 1
match val: case FOO: # obviously matches by constant's value
This would make it *more* difficult to distinguish constants from assignment targets when looking at the match statement, unless you choose names which "look constant-like" somehow. It also has the general problem of const-declarations in Python. Currently the compiler only has to analyse one module at a time; this would require it to also look inside imported modules to determine whether things were declared const. -- Greg

Please move this subtopic to a subject that doesn’t have “PEP 622” in its topic. On Tue, Jul 7, 2020 at 17:54 Greg Ewing <greg.ewing@canterbury.ac.nz> wrote:
On 8/07/20 5:30 am, Paul Sokolovsky wrote:
from __future__ import const
FOO: const = 1
match val: case FOO: # obviously matches by constant's value
This would make it *more* difficult to distinguish constants from assignment targets when looking at the match statement, unless you choose names which "look constant-like" somehow.
It also has the general problem of const-declarations in Python. Currently the compiler only has to analyse one module at a time; this would require it to also look inside imported modules to determine whether things were declared const.
-- Greg _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-leave@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/ACJJV65B... Code of Conduct: http://python.org/psf/codeofconduct/
-- --Guido (mobile)

Hello, On Wed, 08 Jul 2020 12:45:09 +1200 Greg Ewing <greg.ewing@canterbury.ac.nz> wrote:
On 8/07/20 5:30 am, Paul Sokolovsky wrote:
from __future__ import const
FOO: const = 1
match val: case FOO: # obviously matches by constant's value
This would make it *more* difficult to distinguish constants from assignment targets when looking at the match statement, unless you choose names which "look constant-like" somehow.
Sure, the talk was about good technical means to distinguish symbolic constants and variables for pattern matching. These technical means alone are no replacement for stylistic conventions which improve readability of the code. In this regard, it's no different than e.g. conventions of naming classes vs variables.
It also has the general problem of const-declarations in Python. Currently the compiler only has to analyse one module at a time; this would require it to also look inside imported modules to determine whether things were declared const.
Indeed, adding some "const" at the core language level would give many benefits, which certainly would be utilized by (even simple, as embedded in CPython) compilers. E.g. better inter-module scope resolution and optimization, an example of which you give. In terms of complexity, that would be minor comparing to e.g. introducing a parser with unbound memory usage, as done in https://www.python.org/dev/peps/pep-0617 .
-- Greg
-- Best regards, Paul mailto:pmiscml@gmail.com

Whenever someone says "Python is the only language..." it really turns out to be the case. Python is very rarely as unusual as people often make out. To my knowledge, there are quite a few other languages that don't have constants, some of them are even moderately well known languages: - Mathematica - Scheme - Powershell and other scripting languages like bash - Applescript and Hyperscript - Ruby (the compiler only issues a warning if you re-assign to one, it doesn't enforce the constantness). I daresay there are many others. I'm not arguing here for or against constantness, but only pointing out that Python is in good company when it comes to lack of constants. -- Steven

On Thu, Jul 09, 2020 at 01:22:48AM +1000, Steven D'Aprano wrote:
Whenever someone says "Python is the only language..." it really turns out to be the case. Python is very rarely as unusual as people often make out.
Gah, embarrasing typo! That was meant to be *rarely* turns out to be the case, sorry for any confusion. -- Steven

Hello, On Thu, 9 Jul 2020 01:22:48 +1000 Steven D'Aprano <steve@pearwood.info> wrote:
Whenever someone says "Python is the only language..." it really
Yeah, the original message in this sub-thread was https://mail.python.org/archives/list/python-dev@python.org/message/YPP2TWYO... , and started with: ----- With the advent of Lua 5.4, Python appears to be the only of the popular VHLL/scripting languages which doesn't support defining of constants in the core language: JavaScript has "const foo = 1;" PHP has "const foo = 1;" Perl has "use constant foo => 1;" Lua has "local foo <const> = 1" ----- The reply cut off that part, then a request to switch subject came in, and you can fit only so many characters in an email subject, so words "appears to be" and "popular" got skipped.
turns out to be the case. Python is very rarely as unusual as people often make out.
To my knowledge, there are quite a few other languages that don't have constants, some of them are even moderately well known languages:
- Mathematica - Scheme - Powershell and other scripting languages like bash - Applescript and Hyperscript - Ruby (the compiler only issues a warning if you re-assign to one, it doesn't enforce the constantness).
Thanks for mentioning Ruby, dunno how I forgot to look it up. And I'm not surprised that they did something about const'ness, even though they seem to fall into half-measures.
I daresay there are many others.
I'm not arguing here for or against constantness, but only pointing out that Python is in good company when it comes to lack of constants.
There's unlimited number of scripting languages which don't offer const'ness. Any freshman student writing their own first language would make it such. The point made is that among general-purpose, popular scripting languages, many adopted a concept of const'ness to the language core, with Python, sadly, being at the tail. -- Best regards, Paul mailto:pmiscml@gmail.com

On Wed, Jul 8, 2020, 12:22 PM Paul Sokolovsky
popular VHLL/scripting languages which doesn't support defining of constants in the core language:
JavaScript has "const foo = 1;" PHP has "const foo = 1;" Perl has "use constant foo => 1;" Lua has "local foo <const> = 1" -----
- Mathematica - Scheme - Powershell and other scripting languages like bash - Applescript and Hyperscript - Ruby
I'm pretty sure some on Steven's list are more *popular* than some on Paul's list. What methodology for ranking popularity you use might change details. But none of Steven's are rate, obscure, vanity languages.

Hello, On Wed, 8 Jul 2020 12:37:05 -0400 David Mertz <mertz@gnosis.cx> wrote:
On Wed, Jul 8, 2020, 12:22 PM Paul Sokolovsky
popular VHLL/scripting languages which doesn't support defining of constants in the core language:
JavaScript has "const foo = 1;" PHP has "const foo = 1;" Perl has "use constant foo => 1;" Lua has "local foo <const> = 1" -----
- Mathematica - Scheme - Powershell and other scripting languages like bash - Applescript and Hyperscript - Ruby
I'm pretty sure some on Steven's list are more *popular* than some on Paul's list. What methodology for ranking popularity you use might change details. But none of Steven's are rate, obscure, vanity languages.
Right. So, if someone would like to add something to this thread, I'd humbly suggest to concentrate on the lack of, and need for, of const-ness in the Python language core (in comparison to other languages or not), and usecases it enables, and not on criteria for "popularness". -- Best regards, Paul mailto:pmiscml@gmail.com

On Wed, Jul 8, 2020, 1:00 PM Paul Sokolovsky
Right. So, if someone would like to add something to this thread, I'd humbly suggest to concentrate on the lack of, and need for, of const-ness in the Python language core (in comparison to other languages or not), and usecases it enables, and not on criteria for "popularness".
I admit I do not really understand what gain dynamic languages get from constants. I pretty uniformly use a common convention of ALLCAPS for constant names (knowing they are not really const in Python or bash, where I tend to use them). I think that clarifies intent in an important way. But checking it feels like a job for linters, or perhaps for a future mypy or other type checker. I can easily imagine that a VM might gain speed with that information, but that alone does not feel like enough reason for a language change.

Le 8 juil. 2020 à 19:15, David Mertz <mertz@gnosis.cx> a écrit :
On Wed, Jul 8, 2020, 1:00 PM Paul Sokolovsky Right. So, if someone would like to add something to this thread, I'd humbly suggest to concentrate on the lack of, and need for, of const-ness in the Python language core (in comparison to other languages or not), and usecases it enables, and not on criteria for "popularness".
I admit I do not really understand what gain dynamic languages get from constants. I pretty uniformly use a common convention of ALLCAPS for constant names (knowing they are not really const in Python or bash, where I tend to use them).
This is what I see most, and sometimes beginner misunderstand constness with not re-binded names e.g.: LOGGER = logging.getLogger(__name__)
I think that clarifies intent in an important way. But checking it feels like a job for linters, or perhaps for a future mypy or other type checker.
Mypy has Final (https://mypy.readthedocs.io/en/stable/final_attrs.html#final-names): from typing_extensions import Final RATE: Final = 3000 class Base: DEFAULT_ID: Final = 0 RATE = 300 # Error: can't assign to final attribute Base.DEFAULT_ID = 1 # Error: can't override a final attribute
I can easily imagine that a VM might gain speed with that information, but that alone does not feel like enough reason for a language change. _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-leave@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/HZD7TNMZ... Code of Conduct: http://python.org/psf/codeofconduct/

Hello, On Wed, 8 Jul 2020 13:15:19 -0400 David Mertz <mertz@gnosis.cx> wrote:
On Wed, Jul 8, 2020, 1:00 PM Paul Sokolovsky
Right. So, if someone would like to add something to this thread, I'd humbly suggest to concentrate on the lack of, and need for, of const-ness in the Python language core (in comparison to other languages or not), and usecases it enables, and not on criteria for "popularness".
I admit I do not really understand what gain dynamic languages get from constants. I pretty uniformly use a common convention of ALLCAPS for constant names (knowing they are not really const in Python or bash, where I tend to use them).
Roughly speaking, it's the same "gain" as e.g. (type) annotations. Indeed, const'ness is a kind of simple type annotation.
I think that clarifies intent in an important way.
The talk is about formalizing specification of this intent beyond just stylistic conventions, like case of names. E.g.: def foo(): pass bar = foo # bar is a variable which stores a reference to a function # (can be reassigned with another function) baz: const = foo # baz is an alias for foo()
But checking it feels like a job for linters, or perhaps for a future mypy or other type checker.
I can easily imagine that a VM might gain speed with that information, but that alone does not feel like enough reason for a language change.
If people are satisfied with Python's performance story as presented by CPython, perhaps. Because otherwise, having a formal constants in the code allows for simple and obvious optimizations: instead of looking up value by name at runtime, you can use literal value at the compile time. If anything, lack of const in Python looks like an accidental gap (https://en.wikipedia.org/wiki/Accidental_gap): there're general annotations "with almost arbitrary" syntax, but there's no simple annotation with very obvious and useful semantics. There's support for "dict versions" (PEP 509), so you could catch cases when something was changed behind your back, and no means to say that something just should not change behind your back. There's a "meta-tracing" JIT and a number of failed corporate projects, and no means to develop a simple effective JIT, where user in control of making it more optimal (just mark things const and you don't need all those dict versions and runtimes guards, which take space in your instruction cache and put limit on how fast things can be). Finally, there's pattern matching PEP 622, which initially proposed a funny syntax, and now accidental-gap's matching by non-namespaced constants. All this gives feeling that Python skipped development of a simple and useful notion (const'ness, again), and its lack leads to more skips and unbeautiful workarounds with more complex features in the language. -- Best regards, Paul mailto:pmiscml@gmail.com

On Wed, Jul 8, 2020, 1:50 PM Paul Sokolovsky
I admit I do not really understand what gain dynamic languages get from constants. I pretty uniformly use a common convention of ALLCAPS for constant names
I can easily imagine that a VM might gain speed with that information, but that alone does not feel like enough reason for a language change.
If people are satisfied with Python's performance story as presented by CPython, perhaps. Because otherwise, having a formal constants in the code allows for simple and obvious optimizations: instead of looking up value by name at runtime, you can use literal value at the compile time.
Most "obvious" optimizations in the history of Python have not wound up speeding up CPython. If you have a fork that can convince Victor of a noteworthy speed up, my perspective would definitely shift. Stipulating such a win exists (and amounts to more than 1-2%), deciding syntax would be the next question. My personal feeling would be that enshrining the ALLCAPS convention would be nice. That could potentially make existing code become magically faster. Of course, not all code uses that convention, and some violates the constant-ness only sometimes. So deprecation periods and __future__ import, etc.

On Tue, Jul 7, 2020 at 9:09 AM Paul Moore <p.f.moore@gmail.com> wrote:
Hopefully the PEP authors intend to post an updated version (preferably with a summary of changes, for people struggling to keep up with the traffic here!) sometime soon.
Please consider that the PEP authors also are struggling with the traffic here. -- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-c...>

On Tue, 7 Jul 2020 at 18:35, Guido van Rossum <guido@python.org> wrote:
On Tue, Jul 7, 2020 at 9:09 AM Paul Moore <p.f.moore@gmail.com> wrote:
Hopefully the PEP authors intend to post an updated version (preferably with a summary of changes, for people struggling to keep up with the traffic here!) sometime soon.
Please consider that the PEP authors also are struggling with the traffic here.
Sorry! I didn't intend to imply otherwise. Mostly I was just hoping you'd be more aware of what you'd changed and could offer a "these are the high spots of what's changed" overview when you post the new version. But absolutely don't feel that I'm suggesting you're obliged to do so! Paul

On Tue, 7 Jul 2020 at 15:04, Rob Cliffe via Python-Dev < python-dev@python.org> wrote:
I don't like the .name syntax (grit on Tim's monitor; does not
suggest the meaning). [...] But I don't know what syntax (where necessary) to suggest.
https://photos.app.goo.gl/xN68s3QMMBTPTLD47 Look about two character spaces left of "I don't like..." As I read this part of Rob's post this morning, I thought he was surreptitiously making a point about grit on the screen, when I noticed it was *literally grit on the screen*. I cannot convey how long it took me to recover.

On 8/07/20 2:31 am, Henk-Jaap Wagenaar wrote:
Would it be possible here to use a syntax/symbol that is illegal instead of _? I think this has been mooted but my favourite (so far) would be "?" so you have "case ?:" and "Point(?, ?)".
Would ?name then work instead of ".name" as well?
It would work better if ? were used to mark assigned names instead of values. Then '?' on its own would be a special case of '?name' where you leave out the name. -- Greg

On 07/07/2020 16:31, Henk-Jaap Wagenaar wrote:
I used to be in this "camp", however, a (I think valid) point was raised that "else:" is not a (full) alternative. Due to the restriction on repeated names (e.g. Point(x, x) is illegal), if you want to "throw away" intermediate matches, you will have to either have to come up with new names (Point(unused_1, unused_2)) or use the "_" as currently instituted (Point(_, _)) and "else:" does not cover that insofar as I can tell.
Personally I think using _ as throwaway name is perfectly fine, as it is in the rest of Python. The only exception would then be that _ is allowed to be repeated, whereas other identifiers aren't. I'd be ok with that. What I don't like is the use of _ as catch-all, which is different and not interdependent with its use as throwaway. On 08/07/2020 07:26, Steven Barker wrote:
To sum up, I feel like using constructor and keyword-argument syntax to access attributes is an abuse of notation. I'd much prefer a new syntax for matching classes and their attributes that was not so likely to be confusing due to imperfect parallels with class construction. +1
Ideally something like Datetime.year=x would be in my opinion clear at a glance (and reference vs. assignment could be accomplished simply by having == for reference and = for assignment), but it's problematic when it comes to mentioning multiple attributes. A couple ideas: 1. Datetime[year=x, months==3, days==SOME_CONST] 2. (Datetime.year=x, months==3, days==SOME_CONST) 3. Datetime.year=x .months==3 .days==SOME_CONST 4. Datetime.year=x, .months==3, .days==SOME_CONST With no class, this would perhaps favour usage of = and/or == before names to resolve the reference vs. assignment dispute.

On 08/07/2020 11:05, Federico Salerno wrote:
What I don't like is the use of _ as catch-all, which is different and not interdependent with its use as throwaway.
Any name used as a pattern is a catch-all. The only difference between "case dummy:" and "case _:" is that "_" doesn't bind to the thing being matched, but "dummy" does bind to it. -- Rhodri James *-* Kynesim Ltd

On 03/07/2020 21:55, Rob Cliffe wrote:
I don't like the .name syntax (grit on Tim's monitor; does not suggest the meaning). Nor am I keen on "expressions" being interpreted differently after 'case' than elsewhere in Python. But I don't know what syntax (where necessary) to suggest. I'm not keen on special treatment of the '_' variable, and would prefer to be able to use 'else:' after 'match'.
+1 I think using else would be sensible since it has similar behaviour in the rest of Python and it would immediately make sense to anyone seeing the syntax for the first time (provided they understood what the rest of the match block does). If objections were moved against it I seem to have missed them (in my defence, the discussion on PEP622 has been quite fragmented and I haven't been on this list for very long). I also don't like the .name syntax and for what little it's worth, I personally would have a hard time getting used to it if it were adopted. Has anyone proposed introducing ` ` quotes for this purpose? They could enclose references without ambiguity and could even be used elsewhere in Python to enclose identifiers, for example to allow spaces and symbols in them (which I wouldn't regard as particularly good style, but it may still come in handy). They are used in MySQL, bash and Markdown to enclose expressions or identifiers, so I feel no experienced programmer would have a hard time wrapping their head around it. Though I'd understand if it were problematic for Python's parser. Another option would be to wrap references in {} in a similar way to what happens in fstrings. Another option still could be to wrap references in quotes, like strings, and require use of str("some string") to catch literal strings, but I don't know if I like this myself. Either way, I seem to prefer symmetric marks to signal references; I don't know if anyone else shares this sentiment.

On Tue, 7 Jul 2020 at 15:07, Rob Cliffe via Python-Dev < python-dev@python.org> wrote:
(...) Nor am I keen on "expressions" being interpreted differently after 'case' than elsewhere in Python.
Python already has "expressions" (intentional quotes) that are interpreted differently depending on the context. `x` may mean "the value bound to x" in code like `print(x)`, or "the name x inside some scope" when doing `x = 3`. `x[0]` may mean "calling `__getitem__(x, 0)` in the type of x" , or it may mean a call to `__setitem__(x, 0, something)` instead if you do `for x[0] in some_iter`. `[a, *b]` may mean "build a list with a, and all the elements that come from iterating b" in some contexts, in other it might mean "extract one element from an iterator and bind it to a. Then build a list with the other elements of the same iterator, put them into a new list , and bind that to b" if you are doing `[a, *b] = myiter`. Many people in this thread have argued that the double meaning in the PEP might be confusing, but Python already has a double meaning in other places. It's so NOT confusing, that people even forget that exists :) It works because the two meanings are not completely unrelated, and that's what PEP622 is trying to achieve. It may be surprising the first time you read the PEP in the air. The question to answer is if it will be confusing after we've seen this statement half a dozen of times in our codebases. Best, D.
But I don't know what syntax (where necessary) to suggest. I'm not keen on special treatment of the '_' variable, and would prefer to be able to use 'else:' after 'match'.
Best wishes Rob Cliffe
On 03/07/2020 15:56, Chris Angelico wrote:
The PEP is still a draft and has not been accepted. Don't worry, the normal process is still happening :)
Having a reference implementation is a HUGE help, because people can play around with it. There's a fork running an interactive playground so you can go right now and get a feel for the way the syntax works.
The implementation has *not* been merged into the CPython trunk. It's not a fait accompli - it's a tool to help people evaluate the proposal (and all of the different variants of the proposal as it evolves).
Speaking with my PEP Editor hat on, I would be *thrilled* if more proposals came with ready-to-try code. Only a very few have that luxury, and a lot of the debating happens with nothing but theory - people consider what they *think* they'd do, without actually being able to try it out and see if it really does what they expect. Having a reference implementation isn't necessary, of course, but it's definitely a benefit and not a downside. Also, there HAVE been proposals with full reference implementations that have ended up getting rejected; it's not a guarantee that it'll end up getting merged.
Hope that lessens your fears a bit :)
ChrisA _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-leave@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/E5U5Z6RR...
Code of Conduct: http://python.org/psf/codeofconduct/
Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-leave@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/NWNG5KII... Code of Conduct: http://python.org/psf/codeofconduct/

On 8/07/20 12:24 pm, Daniel Moisset wrote:
Many people in this thread have argued that the double meaning in the PEP might be confusing, but Python already has a double meaning in other places.
But assignment targets have always been clearly separated by being on the left of an assignment operator, either = or :=. The PEP proposes to intermingle them, with only very subtle clues, such as the presence or absence of dots, to distinguish them. -- Greg

On Wed, Jul 8, 2020 at 10:45 AM Greg Ewing <greg.ewing@canterbury.ac.nz> wrote:
On 8/07/20 12:24 pm, Daniel Moisset wrote:
Many people in this thread have argued that the double meaning in the PEP might be confusing, but Python already has a double meaning in other places.
But assignment targets have always been clearly separated by being on the left of an assignment operator, either = or :=. The PEP proposes to intermingle them, with only very subtle clues, such as the presence or absence of dots, to distinguish them.
Part of the point of the post you responded to is that assignment targets can be found in other contexts too - "for x[0] in iter:" uses x[0] as an assignment target, and there's no equals sign to be seen. You're right about the presence/absence of a dot being very subtle, but hang tight, wait for the next publication of the PEP; its authors are working on that exact problem. ChrisA

On 8/07/20 12:48 pm, Chris Angelico wrote:
"for x[0] in iter:" uses x[0] as an assignment target,
You're right, there are some others, but I think they're equally clear -- all the ones I can think of are directly after a keyword ("for", "as", "import", etc.) But in match statements, they can be arbitrarily intermingled with other expression-like stuff.
You're right about the presence/absence of a dot being very subtle, but hang tight, wait for the next publication of the PEP; its authors are working on that exact problem.
It looks like the only thing they're doing is dropping the *leading* dot case -- without providing any replacement for it. That only addresses one small part of my concern, since I think the non-leading dot is nearly as subtle. Maybe even more so, since at least the leading dot was obviously something different. Also I don't like the idea of being *forced* to use a namespace for my constants, regardless of how good an idea the PEP authors think it is. -- Greg

On 2020-07-08 02:20, Greg Ewing wrote:
On 8/07/20 12:48 pm, Chris Angelico wrote:
"for x[0] in iter:" uses x[0] as an assignment target,
You're right, there are some others, but I think they're equally clear -- all the ones I can think of are directly after a keyword ("for", "as", "import", etc.)
But in match statements, they can be arbitrarily intermingled with other expression-like stuff.
You're right about the presence/absence of a dot being very subtle, but hang tight, wait for the next publication of the PEP; its authors are working on that exact problem.
It looks like the only thing they're doing is dropping the *leading* dot case -- without providing any replacement for it. That only addresses one small part of my concern, since I think the non-leading dot is nearly as subtle. Maybe even more so, since at least the leading dot was obviously something different.
Also I don't like the idea of being *forced* to use a namespace for my constants, regardless of how good an idea the PEP authors think it is.
Prefixing values with "==" might be the clearest, an idea that, I think, Ethan came up with. It might not look elegant, but...

On Wed, 1 Jul 2020 21:14:00 +0100 Rob Cliffe via Python-Dev <python-dev@python.org> wrote:
Whoa!
I have an uneasy feeling about this PEP.
AFAIK the usual procedure for adding a new feature to Python is: An idea is raised and attracts some support. Someone sufficiently motivated writes a PEP. The PEP is thoroughly discussed. Eventually a consensus (or at least an "agree to differ" stalemate) is reached. The PEP is accepted (if it is). (Then and only then) Someone works on the implementation. etc.
However, PEP 622 only seems to have been presented to the Python community only *after* a well-developed (if not finalised) implementation was built. A fait accompli.
I think what you describe as "the usual procedure" isn't as usual as you think. For example, when I wrote PEP 442 (Safe object finalization), I don't remember a preliminary round of raising support for the idea. I had that idea in mind after repeated frustration with the previous finalization semantics, attempted writing an implementation which ended up functional, and then wrote a PEP from it. That said, PEP 622 is a much broader PEP adding a whole new syntactical feature with unusual semantics attached to it, so it's conceivable to be more cautious with the discussion process. Regards Antoine.

On Fri, Jul 3, 2020, 09:18 Antoine Pitrou <solipsis@pitrou.net> wrote:
I think what you describe as "the usual procedure" isn't as usual as you think.
+1 Also, keep in mind that PEPs are a tool for the decision maker (i.e. BDFL delegate). Effectively, everything else is convention. The process usually involves community feedback, but has never been community-driven. All this has become more painful for volunteers as the Python community has grown. -eric

On Fri, Jul 3, 2020, 12:40 Eric Snow <ericsnowcurrently@gmail.com> wrote:
Also, keep in mind that PEPs are a tool for the decision maker (i.e. BDFL delegate). Effectively, everything else is convention. The process usually involves community feedback, but has never been community-driven. All this has become more painful for volunteers as the Python community has grown.
-eric
To further elaborate on that, a PEP isn't legislation to be approved by the community. Rather, it is meant to capture the proposal and discussion sufficiently that the BDFL/delegate can make a good decision. Ultimately there isn't much more to the process than that, beyond convention. The BDFL-delegate is trusted to do the right thing and the steering council is there as a backstop. It's up to the decision maker to reach a conclusion and it makes sense that they especially consider community impact. However, there is no requirement of community approval. This is not new. Over the years quite a few decisions by Guido (as BDFL) sparked controversy yet in hindsight Python is better for each of those decisions. (See PEP 20.) The main difference in recent years is the growth of the Python community, which is a happy problem even if a complex one. :) There has been a huge influx of folks without context on Python's governance but with contrary expectations and loud voices. On the downside, growth has greatly increased communications traffic and signal-to-noise, as well as somewhat shifting tone in the wrong direction. Unfortunately all this contributed to us losing our BDFL. :( Thankfully we have the steering council as a replacement. Regardless, Python is not run as a democracy nor by a representative body. Instead, this is a group of trusted volunteers that are trying their best to keep Python going and make it better. The sacrifices they make reflect how much they care about the language and the community, especially as dissenting voices increase in volume and vitriol. That negativity has a real impact. -eric

On Fri, Jul 3, 2020 at 4:42 PM Rob Cliffe via Python-Dev < python-dev@python.org> wrote:
And since the PEP has Guido's authority behind it, I think it is likely that it will eventually be accepted pretty much as it was originally written.
This seems a bit unfair to Guido. He seems to put a lot of effort into taking onboard feedback and I would prefer it if the community encouraged long term contributors to keep contributing, rather than suggesting that this was somehow problematic (of course new contributors are good too, as are new-and-old contributors working together). Full disclosure: I'm not a huge fan of this PEP myself -- it seems to add a lot of new syntax to support a coding idiom that I consider an anti-pattern -- but others seem to have raised similar points to mine, so I think my point of view has already been fairly well represented in the discussion.

On Fri, Jul 3, 2020 at 7:39 AM Rob Cliffe via Python-Dev < python-dev@python.org> wrote:
Whoa!
I have an uneasy feeling about this PEP.
AFAIK the usual procedure for adding a new feature to Python is: An idea is raised and attracts some support. Someone sufficiently motivated writes a PEP. The PEP is thoroughly discussed. Eventually a consensus (or at least an "agree to differ" stalemate) is reached. The PEP is accepted (if it is). (Then and only then) Someone works on the implementation.
That "then and only then" part is not correct. It just happens to be typical due to people wanting to see if their idea has any support before putting in the effort to actually code it up. Personally I sometimes wonder if we should require a proof-of-concept upfront for all PEPs that introduce a code change.
etc.
However, PEP 622 only seems to have been presented to the Python community only *after* a well-developed (if not finalised) implementation was built. A fait accompli. So there will inevitably be resistance from the developers to accept changes suggested on python-dev.
Then that's on them. But it may backfire if people don't like what there PEP is presenting.
And since the PEP has Guido's authority behind it, I think it is likely that it will eventually be accepted pretty much as it was originally written.
I'm trying to not take that as an insult, but I will say the steering council does not rubber stamp Guido's PEPs. We do debate them and consider them like any other PEP. It's not our fault he has a good sense of design even in retirement. 😉 So as usual, once this PEP is ready for consideration (which it isn't as stated by the PEP authors), we will consider it like any other PEP that tries to change the language.
This means that most of the discussion we have seen on python-dev (and there has been a lot) will end up being just pissing in the wind.
Once again, it is at the PEP author's peril to not listen to people's suggestions and risk the PEP not being accepted due to the design not meeting standards for acceptance. And they are still required to keep the Rejected Ideas section of the PEP up-to-date or else the PEP will not be considered.
(I don't mean to be vulgar or disrespectful; I just can't think of another phrase that conveys my meaning so well.)
I think you're looking for "ignored". -Brett
And Guido's 2nd email ("PEP 622: Structural Pattern Matching -- followup") already to me (YMMV) reads rather like "OK, you've had your fun, now try not to joggle our elbows too much while we get on with the work".
I don't know how many of the decisions made in the PEP are right and how many could be improved (it is of course a subjective question anyway). I do think it's a pity that the Python community did not have the chance to supply feedback earlier down the road (when IMO it would have been taken more seriously). While Guido and the other developers have obviously already put a huge amount of work into this PEP (and by now probably have a significant emotional investment in it), I do hope that they will take the time to consider seriously and on their merits most/all suggested changes, rather than being tempted to rush through the acceptance and implementation of the PEP.
Best wishes Rob Cliffe _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-leave@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/IG4VNKZF... Code of Conduct: http://python.org/psf/codeofconduct/

On 7/1/2020 4:14 PM, Rob Cliffe via Python-Dev wrote:
I have an uneasy feeling about this PEP.
I can understand that.
AFAIK the usual procedure for adding a new feature to Python is: An idea is raised and attracts some support. Someone sufficiently motivated writes a PEP. The PEP is thoroughly discussed. Eventually a consensus (or at least an "agree to differ" stalemate) is reached. The PEP is accepted (if it is). (Then and only then) Someone works on the implementation. etc.
To the extent that this is true, a big reason is that many people do not want to write code until they are somewhat sure it will be accepted. But we can almost never be sure until we know what the code is, or will be -- in detail. 'Show us some code' is common in discussion. Is the feature possible, or are we wasting out time discussing it? Will it be fast enough? Will the code be maintainable? Or too ugly to look at? The same issue comes up on bpo issues. 'Please either give a really detailed specification, or submit a PR.' 'Will it be accepted?' 'We cannot tell until we see it.' Sometimes, someone not a PEP or bpo issue author offers to contribute an implementation to move discussion along to possible acceptance.
However, PEP 622 only seems to have been presented to the Python community only *after* a well-developed (if not finalised) implementation was built. A fait accompli.
I would be annoyed too if I thought it were true, but I don't. AFAIK, the implementation on someone's private fork has not yet been presented as a PR ready to be committed at the press of the green button.
And since the PEP has Guido's authority behind it, I think it is likely that it will eventually be accepted pretty much as it was originally written.
I suspect that Guido retired from the decision council in part so that he could submit PEP level changes to it as an independent person not on the council. The new PEG parser was the first new PEP. I believe Guido was looking at PEG parsers last summer, before last fall's council election. The theoretical advantage was clear; the practical application to Python not so much. He refrained from submitting a PEP until he had a couple of collaborators to help produce an initial implementation that answered the inevitable questions that would have made discussion without an implementation moot. Is a PEG parser matching the current parser possible?, fast enough?, compact enough?, and 'will there be the needed follow through maintenance'? It is common for a reasonably complicated context free grammar to be ambiguous in the sense that a given sequence of tokens can be produced by more than one sequence of applications of the production rules. But we want machine parsing of code to a particular sequence to be unambiguious, deterministic, and fast. An LL(1) parser uses and is limited to one token lookahead and cannot unambiguously parse all context-free languages. The PEG parser cuts the ambiguity knot by ordering production rules and accepting the first match. This is the same rule proposed for match statements and is similar to the disambiguating rule for if statements in Python and many other languages (but not all): first true condition wins. (Python also does the same for expressions with side-effects with a left-to-right evaluation rule.) Each condition is implicitly augmented with 'and none of the previous conditions'. In ordered matching, each pattern has a similar implicit condition. Ordered evaluation at the expression level is not much of an issue for human readers. I think making words keywords only in certain easily read contexts, such as 'match' followed by <expression> followed by ':', is also not much of an issue. I suspect that some of the proposed match patterns require the new PEP parser and that this has something to do with people's uneasiness. Removing the LL(1) limitation lets us add grammar rules that we want, but also allows for constructions that are unneeded* or hard for humans to read. *Prior to the match proposal, Guido reported on python-ideas that he had developed a PEG grammar and resulting parser and compiler that allowed for omitting parentheses in at least some calls with arguments. He dropped the idea when the coredev reaction was neutral to negative. -- Terry Jan Reedy

Since I took it upon myself to implement PEP 622, I just have a few thoughts to add to the other excellent responses here. Hopefully these will help clarify that the intent is not to "railroad" anything. Rob Cliffe wrote:
PEP 622 only seems to have been presented to the Python community only after a well-developed (if not finalised) implementation was built.
Well, thanks for the "well-developed" bit, but I promise that the implementation is far from final. Since we first published the PEP, I've made dozens of commits touching pretty much every new line of code several times. Just last week we gutted the __match__ method in response to well-reasoned calls to defer it.
So there will inevitably be resistance from the developers to accept changes suggested on python-dev.
As the one who has been doing almost all of the development, I assure you this isn't true. 80% of the PEP's authors have been almost entirely detached from development of the reference implementation, so I would be very surprised if they gave my existing work more weight than the opinions of the community... I wrote the thing, and I certainly don't! I volunteered to implement it because I thought the PEP and implementation would be an interesting project while trapped at home this spring. I *like* doing this stuff, so I'm not really worried about getting to do more of it. ;)
And since the PEP has Guido's authority behind it, I think it is likely that it will eventually be accepted pretty much as it was originally written.
It has already changed quite substantially from how it was originally written. Here's everything that's changed since we posted the first draft (we've been pretty much dominating PEP repo traffic over the past week): https://github.com/python/peps/commits/master/pep-0622.rst Again, you'll notice that the entire __match__ protocol was deferred based on feedback we received, and we've made an effort to describe the reasoning behind many decisions that seemed obvious to us but weren't to others. The opening sections are also getting a rewrite (again, based on Python-Dev feedback).
Guido's 2nd email ("PEP 622: Structural Pattern Matching -- followup") already to me (YMMV) reads rather like "OK, you've had your fun, now try not to joggle our elbows too much while we get on with the work".
That's an extremely odd way to interpret his thread, which exists solely to collect of all of the "unheard" critiques in one central location.
I do think it's a pity that the Python community did not have the chance to supply feedback earlier down the road (when IMO it would have been taken more seriously).
It did. The very first thing we did was perform detailed surveys of 8 different Python-Ideas threads (spanning 9 years), 13 other languages, and a handful of the most popular Python packages for pattern matching. This is not at all the first time this has been brought up by the community; I personally worked my way through hundreds of emails and dozens of documents before writing a single line of code (or PEP).
While Guido and the other developers have obviously already put a huge amount of work into this PEP (and by now probably have a significant emotional investment in it), I do hope that they will take the time to consider seriously and on their merits most/all suggested changes, rather than being tempted to rush through the acceptance and implementation of the PEP.
Don't worry; I have a much stronger emotional connection to Python's continued success and community than to a quarantine project that Guido nerd-sniped me with a few months ago. ;) Brandt

I tried with this code: ``` from dataclasses import dataclass @dataclass class Point: x: int y: int z = 41 def whereis(point): w = 23 match point: case Point(0, 0): print("Origin") case Point(0, y): print(f"Y={y}") case Point(x, 0): print(f"X={x}") case Point(): print("Somewhere else") case 23: print("Not the answer") case w: print("Not the answer, local w") case z: print("The answer") case _: print("other") whereis(42) ``` The output is: ``` Not the answer, local w <>:23: SyntaxWarning: unguarded name capture pattern makes remaining cases unreachable <>:23: SyntaxWarning: unguarded name capture pattern makes remaining cases unreachable <ipython-input-12-a56535d2d86c>:23: SyntaxWarning: unguarded name capture pattern makes remaining cases unreachable case w: ``` I except this function to return "other", But it seems not.

I tried with this code: ``` from dataclasses import dataclass @dataclass class Point: x: int y: int z = 41 def whereis(point): w = 23 match point: case Point(0, 0): print("Origin") case Point(0, y): print(f"Y={y}") case Point(x, 0): print(f"X={x}") case Point(): print("Somewhere else") case 23: print("Not the answer") case w: print("Not the answer, local w") case z: print("The answer") case _: print("other") whereis(42) ``` It retuend: ``` Not the answer, local w <>:23: SyntaxWarning: unguarded name capture pattern makes remaining cases unreachable <>:23: SyntaxWarning: unguarded name capture pattern makes remaining cases unreachable <ipython-input-12-a56535d2d86c>:23: SyntaxWarning: unguarded name capture pattern makes remaining cases unreachable case w: ``` It seems not the return I except.

On Wed, Jul 08, 2020 at 07:53:00AM -0000, Kerwin Sun wrote:
I tried with this code: ``` from dataclasses import dataclass
@dataclass class Point: x: int y: int
z = 41
def whereis(point): w = 23 match point: case Point(0, 0): print("Origin") case Point(0, y): print(f"Y={y}") case Point(x, 0): print(f"X={x}") case Point(): print("Somewhere else") case 23: print("Not the answer") case w: print("Not the answer, local w") case z: print("The answer") case _: print("other") whereis(42) ```
It retuend: ``` Not the answer, local w
That looks like the correct answer, "w" is a new binding. This is the same in Standard ML and OCaml: # let whereis point = let w = 23 in match point with 23 -> "Not the answer" | w -> "Correct answer" | _ -> "Unreachable";; Warning 26: unused variable w. Warning 11: this match case is unused. val whereis : int -> string = <fun> # whereis 42;; - : string = "Correct answer" # Stefan Krah

On Wed, Jul 8, 2020 at 7:03 AM Kerwin Sun <sunkaihuisos@gmail.com> wrote:
I tried with this code:
[...]
def whereis(point): case w: print("Not the answer, local w") case z: print("The answer") case _: print("other") whereis(42)
w, z and _ are all equivalent here, therefore it will take the first matching branch. The very first post about 622 contained a caveat that case _: will never be reached if case identifier: exists instead. Equivalent branches are only ignored, not illegal.

On Wed, 1 Jul 2020 at 17:09, Guido van Rossum <guido@python.org> wrote:
If you are interested in learning more about how PEP 622 would work in practice, but don't feel like compiling a Python 3.10 fork from source, here's good news for you.
In a hurry? https://mybinder.org/v2/gh/gvanrossum/patma/master?urlpath=lab/tree/playgrou...
I could not get this to work yesterday and today. It will eventually say: "Your session is taking longer than usual to start! Check the log messages below to see what is happening." But the logs are empty. Is that just me or anybody else too? I tried Chrome (Windows 10 & macOS) and Safari (macOS).
This will open a Binder instance that runs a Jupyter kernel built from Brandt Bucher's fork of Python 3.10 that includes the match statement. This is a complete implementation of the PEP. (Note that we've already made some design changes in response to feedback, but the basic syntax is still the same. Expect a new draft within a week.)
The code for the playground was contributed by Fernando Perez, Matthias Bussonnier and Chris Holdgraf. We also thank the Binder and Jupyter teams for Binder and Jupyter and all the infrastructure that made this playground possible, and we thank gesis.org for hosting.
For details, see https://github.com/gvanrossum/patma/tree/master/binder
-- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-c...> _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-leave@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/47YR2LUT... Code of Conduct: http://python.org/psf/codeofconduct/

It works for me. Did you click on the box where the logs are supposed to appear? It will only show the logs when you click there. On Wed, Jul 8, 2020 at 1:36 PM Henk-Jaap Wagenaar < wagenaarhenkjaap@gmail.com> wrote:
On Wed, 1 Jul 2020 at 17:09, Guido van Rossum <guido@python.org> wrote:
If you are interested in learning more about how PEP 622 would work in practice, but don't feel like compiling a Python 3.10 fork from source, here's good news for you.
In a hurry? https://mybinder.org/v2/gh/gvanrossum/patma/master?urlpath=lab/tree/playgrou...
I could not get this to work yesterday and today. It will eventually say:
"Your session is taking longer than usual to start! Check the log messages below to see what is happening."
But the logs are empty. Is that just me or anybody else too?
I tried Chrome (Windows 10 & macOS) and Safari (macOS).
This will open a Binder instance that runs a Jupyter kernel built from Brandt Bucher's fork of Python 3.10 that includes the match statement. This is a complete implementation of the PEP. (Note that we've already made some design changes in response to feedback, but the basic syntax is still the same. Expect a new draft within a week.)
The code for the playground was contributed by Fernando Perez, Matthias Bussonnier and Chris Holdgraf. We also thank the Binder and Jupyter teams for Binder and Jupyter and all the infrastructure that made this playground possible, and we thank gesis.org for hosting.
For details, see https://github.com/gvanrossum/patma/tree/master/binder
-- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-c...> _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-leave@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/47YR2LUT... Code of Conduct: http://python.org/psf/codeofconduct/
_______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-leave@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/4IUCFYIU... Code of Conduct: http://python.org/psf/codeofconduct/
-- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-c...>

On Wed, 8 Jul 2020 at 21:44, Guido van Rossum <guido@python.org> wrote:
It works for me. Did you click on the box where the logs are supposed to appear? It will only show the logs when you click there.
I did click on that before, but I suddenly had a thought (I should have had long ago): it seems my combination of Ghostery and uBlock on Chrome does not play nicely with mybinder (which is why the logs were empty). Not sure why Safari had the same/a different issue: I do not normally use it or have anything installed on it. Apologies for the noise.
participants (27)
-
Antoine Pitrou
-
Brandt Bucher
-
Brett Cannon
-
Chris Angelico
-
Daniel Moisset
-
David Mertz
-
Emily Bowman
-
Eric Fahlgren
-
Eric Snow
-
Federico Salerno
-
Greg Ewing
-
Guido van Rossum
-
Henk-Jaap Wagenaar
-
Kerwin Sun
-
Matthias Bussonnier
-
MRAB
-
Paul Moore
-
Paul Sokolovsky
-
Rhodri James
-
Rob Cliffe
-
Robert Collins
-
Rémi Lapeyre
-
Simon Cross
-
Stefan Krah
-
Steven D'Aprano
-
Terry Reedy
-
Walter Dörwald