Skip to content

Conversation

@encukou
Copy link
Member

@encukou encukou commented Jan 9, 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/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.

@encukou
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
@miss-islington-app
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>
@bedevere-app
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants