Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-143054: Disallow non-top-level Cut for now #143622

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
encukou merged 3 commits into python:main from encukou:clarify-cut
Jan 13, 2026
Merged

Conversation

@encukou
Copy link
Member

@encukou encukou commented Jan 9, 2026
edited by github-actions bot
Loading

The behaviour of Cut in nested parentheses, Repeat, Opt, and similar is somewhat chaotic. Apparently even the academic papers on PEG aren't as clear as they could be.

And it doesn't really matter. Python only uses top-level cuts. When/if that changes, we can clarify as much as necessary (and even change the implementation to make sense for what we'll need).

For now, document that this is deliberately unspecified, and add a test to make sure any decision is deliberate, tested and documented.


📚 Documentation preview 📚: https://cpython-previews--143622.org.readthedocs.build/

The behaviour of Cut in nested parentheses, Repeat, Opt, and similar
is somewhat chaotic. Apparently even the academic papers on PEG aren't
as clear as they could be.
And it doesn't really matter. Python only uses top-level cuts.
When that changes, we can clarify as much as necessary (and even
change the implementation to make sense for what we'll need).
Document that this is deliberately unspecified, and add a test to
make sure any decision is deliberate, tested and documented.
Copy link
Member

@pablogsal pablogsal left a comment

Choose a reason for hiding this comment

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

This LGTM! I feel you regarding how chaotic this is and how unintuitive the consequences are so I think adding these tests and the docs is perfect and improves the situation. Thanks a lot!

I will recommend to wait for @lysnikolaou to take a look if possible

Copy link
Member

@lysnikolaou lysnikolaou left a comment

Choose a reason for hiding this comment

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

LGTM! This certainly is an improvement over leaving stuff undocumented. I doubt there'll be the need for non-top-level cuts anytime soon anyway.

Copy link
Member Author

encukou commented Jan 13, 2026

Thank you for the reviews -- and for pegen itself!

@encukou encukou merged commit f0a0467 into python:main Jan 13, 2026
61 checks passed
@encukou encukou added awaiting merge 3.14 bugs and security fixes labels Jan 13, 2026
@encukou encukou deleted the clarify-cut branch January 13, 2026 12:22
@encukou encukou added needs backport to 3.14 bugs and security fixes and removed 3.14 bugs and security fixes labels Jan 13, 2026
Copy link

Thanks @encukou for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jan 13, 2026
The behaviour of Cut in nested parentheses, Repeat, Opt, and similar
is somewhat chaotic. Apparently even the academic papers on PEG aren't
as clear as they could be.
And it doesn't really matter. Python only uses top-level cuts.
When that changes, we can clarify as much as necessary (and even
change the implementation to make sense for what we'll need).
Document that this is deliberately unspecified, and add a test to
make sure any decision is deliberate, tested and documented.
(cherry picked from commit f0a0467)
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Copy link

bedevere-app bot commented Jan 13, 2026

GH-143790 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Jan 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@pablogsal pablogsal pablogsal approved these changes

@lysnikolaou lysnikolaou lysnikolaou approved these changes

@willingc willingc Awaiting requested review from willingc willingc is a code owner

@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /