Skip to content

Update test_grammar.py to 3.14.5#7913

Merged
youknowone merged 12 commits into
RustPython:mainfrom
ShaharNaveh:update-test-grammar
May 19, 2026
Merged

Update test_grammar.py to 3.14.5#7913
youknowone merged 12 commits into
RustPython:mainfrom
ShaharNaveh:update-test-grammar

Conversation

@ShaharNaveh
Copy link
Copy Markdown
Contributor

@ShaharNaveh ShaharNaveh commented May 18, 2026

Summary by CodeRabbit

  • Bug Fixes
    • Improved error messages for syntax validation and parsing errors
    • Enhanced error reporting for loop control statements and additional edge cases in validation
    • Updated feedback text for better clarity on invalid syntax

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 18, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 58e849ed-fc1c-4d26-b482-9aea6af87f43

📥 Commits

Reviewing files that changed from the base of the PR and between e8d7437 and d332789.

⛔ Files ignored due to path filters (2)
  • Lib/test/test_grammar.py is excluded by !Lib/**
  • Lib/test/test_syntax.py is excluded by !Lib/**
📒 Files selected for processing (3)
  • crates/codegen/src/compile.rs
  • crates/codegen/src/error.rs
  • crates/vm/src/vm/vm_new.rs
💤 Files with no reviewable changes (1)
  • crates/codegen/src/compile.rs

📝 Walkthrough

Walkthrough

This PR refines error handling in the RustPython compiler by updating error message text, expanding parse error to syntax error mapping with four new cases, and removing overly strict validation for exception type syntax.

Changes

Error Handling and Validation Refinements

Layer / File(s) Summary
Error message improvements
crates/codegen/src/error.rs
The Display impl for CodegenErrorType is refactored to use explicit Self:: patterns instead of glob imports. The InvalidContinue error message is updated to "'continue' not properly in loop" from "'continue' outside loop".
Extended parse error to syntax error mapping
crates/vm/src/vm/vm_new.rs
The new_syntax_error_maybe_incomplete function adds support for EmptyTypeParams, InvalidStarPatternUsage (with narrow caret enabled), ExpectedKeywordParam, and EmptyImportNames parse error variants. The OtherError handler now also recognizes and maps "positional patterns cannot follow keyword patterns" messages.
Relaxed exception type validation
crates/codegen/src/compile.rs
The compiler removes the syntax check that rejected unparenthesized tuple exception types, allowing exception type expressions to compile without that guard.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • youknowone

Poem

🐰 When errors dance and messages sing,
We polish each word, refine the ring,
Remove the guards that were too tight,
Map new patterns into light! ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The PR title claims to update test_grammar.py to 3.14.5, but the actual changes are in compiler and VM code (compile.rs, error.rs, vm_new.rs) with no modifications to test_grammar.py. Revise the title to accurately reflect the actual changes, such as 'Remove unparenthesized tuple exception type syntax check and improve error messages' or 'Update compiler syntax validation and error handling'.
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 18, 2026

📦 Library Dependencies

The following Lib/ modules were modified. Here are their dependencies:

[ ] test: cpython/Lib/test/test_grammar.py (TODO: 12)

dependencies:

dependent tests: (no tests depend on grammar)

[ ] test: cpython/Lib/test/test_syntax.py (TODO: 356)

dependencies:

dependent tests: (no tests depend on syntax)

Legend:

  • [+] path exists in CPython
  • [x] up-to-date, [ ] outdated

@ShaharNaveh ShaharNaveh marked this pull request as ready for review May 19, 2026 10:26
}
else if s.eq_ignore_ascii_case("positional patterns cannot follow keyword patterns") {
msg = "positional patterns follow keyword patterns".to_owned();
}
Copy link
Copy Markdown
Contributor Author

@ShaharNaveh ShaharNaveh May 19, 2026

Choose a reason for hiding this comment

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

I'd wish to extract this entire match block to its own function, I'll do it as a followup PR.

@ShaharNaveh ShaharNaveh requested a review from youknowone May 19, 2026 11:09
@youknowone youknowone merged commit 0a2461a into RustPython:main May 19, 2026
27 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.

2 participants