Skip to content

Validate SyntaxError details tuple shape#7533

Merged
youknowone merged 1 commit intoRustPython:mainfrom
wheevu:fix/syntaxerror-details-tuple-validation
Mar 29, 2026
Merged

Validate SyntaxError details tuple shape#7533
youknowone merged 1 commit intoRustPython:mainfrom
wheevu:fix/syntaxerror-details-tuple-validation

Conversation

@wheevu
Copy link
Copy Markdown
Contributor

@wheevu wheevu commented Mar 29, 2026

Validate SyntaxError(message, details_tuple) shape handling in PySyntaxError::slot_init.

Accept 4-item and 6-item tuples, and raise TypeError for invalid tuple lengths, including 5-item tuples with end_lineno but no end_offset.

Also removes the @unittest.expectedFailure marker from test_incorrect_constructor.

Summary by CodeRabbit

  • Bug Fixes
    • Improved syntax error validation when location information is provided. The system now strictly validates the number of location arguments and raises specific, informative error messages when required parameters are missing or an incorrect number of arguments is supplied. This prevents silent failures and enhances error diagnostics for developers working with exception handling.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 29, 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: 9a15072a-c4ef-4bc8-8c33-46f4137a3d25

📥 Commits

Reviewing files that changed from the base of the PR and between 6826557 and afcb2b7.

⛔ Files ignored due to path filters (1)
  • Lib/test/test_exceptions.py is excluded by !Lib/**
📒 Files selected for processing (1)
  • crates/vm/src/exceptions.rs

📝 Walkthrough

Walkthrough

The change adds explicit tuple length validation to PySyntaxError initialization. When a PyTuple is passed as the location argument, the code now verifies it has exactly 4 or 6 elements, rejecting length 5 with a specific error message and other lengths with a function signature error.

Changes

Cohort / File(s) Summary
PySyntaxError Tuple Validation
crates/vm/src/exceptions.rs
Added explicit validation for location tuple size during initialization, accepting only lengths 4 or 6, with targeted error messages for invalid lengths.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A tuple walked into the syntax tree,
"Are you four?" the validator did see.
"Or perhaps six?" it hopped with glee,
Five's rejected—no way to be free! 🌟

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding validation for the SyntaxError details tuple shape, which is exactly what the PR implements.

✏️ 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

📦 Library Dependencies

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

[x] test: cpython/Lib/test/test_exceptions.py (TODO: 24)
[ ] test: cpython/Lib/test/test_baseexception.py
[x] test: cpython/Lib/test/test_except_star.py (TODO: 1)
[x] test: cpython/Lib/test/test_exception_group.py (TODO: 3)
[x] test: cpython/Lib/test/test_exception_hierarchy.py (TODO: 2)
[x] test: cpython/Lib/test/test_exception_variations.py

dependencies:

dependent tests: (no tests depend on exception)

Legend:

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

Copy link
Copy Markdown
Member

@youknowone youknowone left a comment

Choose a reason for hiding this comment

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

👍

@youknowone youknowone merged commit e6bcd64 into RustPython:main Mar 29, 2026
28 of 29 checks passed
@wheevu wheevu deleted the fix/syntaxerror-details-tuple-validation branch March 30, 2026 09:27
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