Skip to content
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

Raise syntax error for mixing except and except* #14895

Merged
merged 6 commits into from
Dec 10, 2024

Conversation

dylwil3
Copy link
Collaborator

@dylwil3 dylwil3 commented Dec 10, 2024

This PR adds a syntax error if the parser encounters a TryStmt that has except clauses both with and without a star.

The displayed error points to each except clause that contradicts the original except clause kind. So, for example,

try:
    ....
except:     #<-- we assume this is the desired except kind
    ....
except*:    #<---  error will point here
    ....
except*:    #<--- and here
    ....

Closes #14860

Copy link
Contributor

github-actions bot commented Dec 10, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@AlexWaygood AlexWaygood added parser Related to the parser bug Something isn't working labels Dec 10, 2024
@dylwil3 dylwil3 marked this pull request as ready for review December 10, 2024 19:29
@dylwil3
Copy link
Collaborator Author

dylwil3 commented Dec 10, 2024

It's not clear to me if it would be better to just put a single displayed error on the entire TryStmt? Happy to change it.

@dylwil3 dylwil3 changed the title [WIP] Raise syntax error for mixing except and except* Raise syntax error for mixing except and except* Dec 10, 2024
Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

I think the syntax error is fine the way it is. Thank you

crates/ruff_python_parser/src/parser/statement.rs Outdated Show resolved Hide resolved
@dylwil3 dylwil3 merged commit a3bb0cd into astral-sh:main Dec 10, 2024
21 checks passed
@dylwil3 dylwil3 deleted the star-except branch December 10, 2024 23:51
TheBits pushed a commit to TheBits/ruff that referenced this pull request Dec 11, 2024
This PR adds a syntax error if the parser encounters a `TryStmt` that
has except clauses both with and without a star.

The displayed error points to each except clause that contradicts the
original except clause kind. So, for example,

```python
try:
    ....
except:     #<-- we assume this is the desired except kind
    ....
except*:    #<---  error will point here
    ....
except*:    #<--- and here
    ....
```

Closes astral-sh#14860
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working parser Related to the parser
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Raise syntax error if there are both except and except* in the same try block
3 participants