-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[syntax-errors] except*
before Python 3.11
#16446
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
Conversation
CodSpeed Performance ReportMerging #16446 will not alter performanceComparing Summary
|
Summary -- One of the simpler ones, just detect the use of `except*` before 3.11. Test Plan -- New inline tests. I'm thinking it may be okay to leave out linter CLI tests for these since we have a few tests for the plumbing already, but I'm happy to add those again if that's preferable.
2f7acbd
to
c2600ef
Compare
`flake8_bugbear/B904.py` was failing and just needed 3.11 but this could be a recurring issue as we add more syntax errors, so just bump to latest
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, we don't need more CLI test here. The inline tests are sufficient and easier to maintain.
| | ||
1 | # parse_options: {"target-version": "3.10"} | ||
2 | / try: ... | ||
3 | | except* ValueError: ... | ||
| |_______________________^ Syntax Error: Cannot use `except*` on Python 3.10 (syntax was added in Python 3.11) | ||
| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'd prefer to just highlight the except*
part instead of the entire try
statement. Pyright only highlights the *
token..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah okay. I did try that at one point, but I wasn't sure how to handle multiple except*
lines after the first. It looks like pyright
emits a separate error for each one, which makes sense.
Summary -- This is a follow-up to #16446 to fix the diagnostic range. Storing the range in the `ExceptClauseKind::Star` variant feels slightly awkward, but we don't store the star itself anywhere on the `ExceptHandler`. And we can't just take `ExceptHandler.start() + "except".text_len()` because this code appears to be valid: ```python try: ... except * Error: ... ``` Test Plan -- Existing tests.
Summary -- This is a follow-up to #16446 to fix the diagnostic range to point to the `*` like `pyright` does (#16446 (comment)). Storing the range in the `ExceptClauseKind::Star` variant feels slightly awkward, but we don't store the star itself anywhere on the `ExceptHandler`. And we can't just take `ExceptHandler.start() + "except".text_len()` because this code appears to be valid: ```python try: ... except * Error: ... ``` Test Plan -- Existing tests.
Summary
One of the simpler ones, just detect the use of
except*
before 3.11.Test Plan
New inline tests.
I'm thinking it may be okay to leave out linter CLI tests for these since we have a few tests for the plumbing already, but I'm happy to add those again if that's preferable.