bpo-42128: Structural Pattern Matching (PEP 634)#22917
Conversation
This currently segfaults but I still like it
|
Gotcha. Yeah, I was referring to the next alpha, scheduled for 3/1. I thought maybe you might need a day or two between tagging and releasing or something. |
Sorry, something went wrong.
No, although is a multi-hour process, I normally do it on the same day as the release, at least for the alphas (assuming everything goes smoothly). |
Sorry, something went wrong.
willingc
left a comment
There was a problem hiding this comment.
@brandtbucher I did an initial pass and it looks good for alpha. I will look at it more closely this weekend.
Sorry, something went wrong.
|
found a bit of an odd case while trying this out -- not sure if it's intentional: x = 1
match x:
case 1 as y if 0:
print('unreachable')
print(f'{y=}') # expect NameErrorinstead of NameError I get |
Sorry, something went wrong.
IIRC I think that is covered in https://www.python.org/dev/peps/pep-0634/#side-effects-and-undefined-behavior, although the peephole could detect the branch and optimize it away. |
Sorry, something went wrong.
|
Yeah, we're required to bind any names used by the guard before evaluating it (obviously). The current naive implementation accomplishes this by binding all names before hitting any guard. Strange example, but legal by the PEP. I'm actually not sure the peephole/CFG could catch this (it can optimize out the body of the case, though, and it actually does here). Might be something for the AST optimizer. |
Sorry, something went wrong.
|
I believe I have addressed all of the comments so far. If anyone still has additional feedback (or needs the weekend to review), please let me know. Otherwise, I'll plan on merging this Friday. @pablogsal, should we hit it with the buildbots again? |
Sorry, something went wrong.
|
🤖 New build scheduled with the buildbot fleet by @pablogsal for commit 61616fc 🤖 If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again. |
Sorry, something went wrong.
|
The three failed jobs look unrelated to these changes; I see the same failures (with the same logs) on #24643. |
Sorry, something went wrong.
|
Okay, I'm going to merge this. 🍾 Big thanks to everyone who took time to help out here! |
Sorry, something went wrong.
Co-authored-by: Guido van Rossum <guido@python.org> Co-authored-by: Talin <viridia@gmail.com> Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
PEP 634 has now been accepted, and we'd like to get this into the next alpha.
Several people have volunteered to review the implementation, since it's so huge. Other reviews are very welcome, if anybody has a bit of time to pitch in. This touches tons of stuff: the parser, the compiler, the VM, the builtins, the stdlib, the tests... I'd like as many eyeballs as possible!
https://bugs.python.org/issue42128