Skip to content

gh-136616: Improve assert syntax error messages #136653

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

sobolevn
Copy link
Member

@sobolevn sobolevn commented Jul 14, 2025

Local testing of positions and code highlight:

Снимок экрана 2025-07-14 в 17 09 57

@sobolevn
Copy link
Member Author

Снимок экрана 2025-07-15 в 11 59 52

Comment on lines 1308 to 1312
| 'assert' expression ',' a=expression '=' b=expression {
RAISE_SYNTAX_ERROR_KNOWN_RANGE(
a, b,
"cannot assign to %s here. Maybe you meant '==' instead of '='?",
_PyPegen_get_expr_name(a)) }
Copy link
Member

Choose a reason for hiding this comment

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

Is the second alternative here needed in reality. If someone's using the second argument here and have a comparison there, maybe they're confused and meant something completely different?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm, good question. They might. For example, assert some.method() == other.method(), some == other might be a realiastic case. But, I am open to other opinions :)

@sobolevn
Copy link
Member Author

 trim trailing whitespace.................................................Failed
- hook id: trailing-whitespace
- exit code: 1
- files were modified by this hook

Fixing Grammar/python.gram

This is a bit annoying. I opened #136680 to fix this.

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