-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[syntax-errors] Fix star annotation before Python 3.11 #16878
Conversation
Summary -- Fixes #16874. I previously emitted a syntax error when starred annotations were _allowed_ rather than when they were actually used. This caused false positives for any starred parameter name because these are allowed to have starred annotations but not required to. The fix is to check if the annotation is actually starred after parsing it. Test Plan -- New inline parser tests derived from the initial report and more examples from the comments, although I think the first case should cover them all.
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.
Do we get an ecosystem report for the syntax-error checks? That could have helped us catch this before it landed
We do , but it was clean: #16545 (comment) |
Maybe it's not actually checking for them, I guess that's what you reallly meant 🤦 |
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
SyntaxError: | 2751 | 0 | 2751 | 0 | 0 |
Formatter (stable)
✅ ecosystem check detected no format changes.
Formatter (preview)
✅ ecosystem check detected no format changes.
It looks like |
Huh, is that the correct behaviour? I'd want to know about syntax errors in my code even if I specified that option, I think 😄 |
I don't think so, I'm working on a separate fix for that! |
Summary -- This updates the regex in `ruff-ecosystem` to catch syntax errors in an effort to prevent bugs like #16874. This should catch `ParseError`s, `UnsupportedSyntaxError`s, and the upcoming `SemanticSyntaxError`s. Test Plan -- I ran the ecosystem check locally comparing v0.11.0 and v0.11.1 and saw a large number (2757!) of new syntax errors. I also manually tested the regex on a few lines before that. If we merge this before #16878, I'd expect to see that number decrease substantially in that PR too, as another test.
I was just in too much of a hurry before 😅 |
Summary -- This updates the regex in `ruff-ecosystem` to catch syntax errors in an effort to prevent bugs like #16874. This should catch `ParseError`s, `UnsupportedSyntaxError`s, and the upcoming `SemanticSyntaxError`s. Test Plan -- I ran the ecosystem check locally comparing v0.11.0 and v0.11.1 and saw a large number (2757!) of new syntax errors. I also manually tested the regex on a few lines before that. If we merge this before #16878, I'd expect to see that number decrease substantially in that PR too, as another test.
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.
We may want to consider doing a patch release for this change (doesn't have to be today). Especially considering that we probably won't do a release next week
That sounds like a good idea. I closed and reopened to update the ecosystem report, and it's now showing -2751 violations. |
* main: (26 commits) Use the common `OperatorPrecedence` for the parser (#16747) [red-knot] Check subtype relation between callable types (#16804) [red-knot] Check whether two callable types are equivalent (#16698) [red-knot] Ban most `Type::Instance` types in type expressions (#16872) Special-case value-expression inference of special form subscriptions (#16877) [syntax-errors] Fix star annotation before Python 3.11 (#16878) Recognize `SyntaxError:` as an error code for ecosystem checks (#16879) [red-knot] add test cases result in false positive errors (#16856) Bump 0.11.1 (#16871) Allow discovery of venv in VIRTUAL_ENV env variable (#16853) Split git pathspecs in change determination onto separate lines (#16869) Use the correct base commit for change determination (#16857) Separate `BitXorOr` into `BitXor` and `BitOr` precedence (#16844) Server: Allow `FixAll` action in presence of version-specific syntax errors (#16848) [`refurb`] Fix starred expressions fix (`FURB161`) (#16550) [`flake8-executable`] Add pytest and uv run to help message for `shebang-missing-python` (`EXE003`) (#16855) Show more precise messages in invalid type expressions (#16850) [`flake8-executables`] Allow `uv run` in shebang line for `shebang-missing-python` (`EXE003`) (#16849) Add `--exit-non-zero-on-format` (#16009) [red-knot] Ban list literals in most contexts in type expressions (#16847) ...
Summary
Fixes #16874. I previously emitted a syntax error when starred annotations were allowed rather than when they were actually used. This caused false positives for any starred parameter name because these are allowed to have starred annotations but not required to. The fix is to check if the annotation is actually starred after parsing it.
Test Plan
New inline parser tests derived from the initial report and more examples from the comments, although I think the first case should cover them all.