Skip to content

Match CPython class generator syntax error - #5

Merged
youknowone merged 1 commit into
mainfrom
rustpython-class-base-syntax
Aug 31, 2026
Merged

Match CPython class generator syntax error#5
youknowone merged 1 commit into
mainfrom
rustpython-class-base-syntax

Conversation

@youknowone

@youknowone youknowone commented Aug 31, 2026

Copy link
Copy Markdown
Member

RustPython uses the parser diagnostic text for SyntaxError. CPython reports invalid syntax for an unparenthesized generator expression in a class base, while calls retain the more specific generator-parenthesization diagnostic.

This makes the class-definition diagnostic context-specific and updates the parser snapshot.

Assisted-by: Codex:GPT-5

Summary by CodeRabbit

  • Bug Fixes
    • Improved syntax error reporting for unparenthesized generator expressions in class definitions.
    • Preserved the existing, more specific error message for generator expressions used in function calls.

@coderabbitai

coderabbitai Bot commented Aug 31, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: c7df0d69-d25d-40f4-bad8-1e4368bc19c4

📥 Commits

Reviewing files that changed from the base of the PR and between fa9dfbb and 079f915.

⛔ Files ignored due to path filters (1)
  • crates/ruff_python_parser/tests/snapshots/invalid_syntax@class_def_unparenthesized_generator_argument.py.snap is excluded by !**/*.snap
📒 Files selected for processing (1)
  • crates/ruff_python_parser/src/parser/expression.rs

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The parser now reports UnparenthesizedGeneratorExpression for call arguments and OtherError("invalid syntax") for class-definition arguments.

Changes

Generator expression error handling

Layer / File(s) Summary
Context-aware argument validation
crates/ruff_python_parser/src/parser/expression.rs
validate_arguments keeps the existing error for ArgumentsContext::Call and reports OtherError("invalid syntax") for ArgumentsContext::ClassDefinition.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Merge Risk: ⚪ Minimal · up to 079f9

The change only adjusts the syntax-error message for an already-invalid class base while preserving the existing behavior for call expressions. No actionable merge-blocking risk remains beyond normal checks and review.

Suggested reviewers: dhruvmanila, michareiser

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main change: matching CPython's syntax error for generator expressions in class definitions.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch rustpython-class-base-syntax

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@youknowone
youknowone merged commit df59fe4 into main Aug 31, 2026
25 of 26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant