◐ Shell
reader mode source ↗
Skip to content

bpo-42128: Structural Pattern Matching (PEP 634)#22917

Merged
brandtbucher merged 260 commits into
python:masterfrom
brandtbucher:patma
Feb 26, 2021
Merged

bpo-42128: Structural Pattern Matching (PEP 634)#22917
brandtbucher merged 260 commits into
python:masterfrom
brandtbucher:patma

Conversation

@brandtbucher

@brandtbucher brandtbucher commented Oct 23, 2020

Copy link
Copy Markdown
Member

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

303 hidden items Load more…
@brandtbucher

brandtbucher commented Feb 19, 2021

Copy link
Copy Markdown
Member Author

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.

@pablogsal

pablogsal commented Feb 19, 2021

Copy link
Copy Markdown
Member

I thought maybe you might need a day or two between tagging and releasing or something.

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).

@willingc willingc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hide comment

@brandtbucher I did an initial pass and it looks good for alpha. I will look at it more closely this weekend.

@asottile

Copy link
Copy Markdown
Contributor

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 NameError

instead of NameError I get y=1

@pablogsal

Copy link
Copy Markdown
Member

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 NameError

instead of NameError I get y=1

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.

@brandtbucher

brandtbucher commented Feb 20, 2021

Copy link
Copy Markdown
Member Author

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.

@brandtbucher

Copy link
Copy Markdown
Member Author

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?

@pablogsal pablogsal added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Feb 24, 2021
@bedevere-bot

Copy link
Copy Markdown

🤖 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.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Feb 24, 2021
@brandtbucher

brandtbucher commented Feb 25, 2021

Copy link
Copy Markdown
Member Author

The three failed jobs look unrelated to these changes; I see the same failures (with the same logs) on #24643.

@brandtbucher

Copy link
Copy Markdown
Member Author

Okay, I'm going to merge this. 🍾

Big thanks to everyone who took time to help out here!

@brandtbucher brandtbucher merged commit 145bf26 into python:master Feb 26, 2021
adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 13, 2021
Co-authored-by: Guido van Rossum <guido@python.org>
Co-authored-by: Talin <viridia@gmail.com>
Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
@brandtbucher brandtbucher deleted the patma branch July 21, 2022 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sprint type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.