-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[flake8-pyi
]: Stabilize: Provide more automated fixes for duplicate-union-members
(PYI016
)
#15342
Conversation
…e-union-members` (PYI016)
flake8-pyi
]: Stabilize: Provide more automated fixes for duplicate-union-members
(PYI016)flake8-pyi
]: Stabilize: Provide more automated fixes for duplicate-union-members
(PYI016
)
// Generate a [`Fix`] for a single type expression, e.g. `int`. | ||
Some(Fix::applicable_edit( | ||
Edit::range_replacement(checker.generator().expr(edit_expr), expr.range()), | ||
// Mark [`Fix`] as unsafe when comments are in range. |
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.
It seems like #14270 incorrectly removed the fix for non-preview 🤷 So, technically, this PR makes the rule fixable again
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.
hehe, onwards and upwards!
|
code | total | + violation | - violation | + fix | - fix |
---|---|---|---|---|---|
PYI016 | 10 | 0 | 0 | 10 | 0 |
Linter (preview)
✅ ecosystem check detected no linter changes.
@@ -111,3 +111,8 @@ def func2() -> str | str: # PYI016: Duplicate union member `str` | |||
|
|||
# Test case for mixed union type | |||
field34: typing.Union[list[int], str] | typing.Union[bytes, list[int]] # Error | |||
|
|||
|
|||
field35: "int | str" | int # Error, but currently not detected |
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'm not sure I'd want to extend the rule to detect this, since:
- It seems like an unlikely edge case
- It will fail at runtime with
TypeError
unless you havefrom __future__ import annotations
at the top of the file (and if you do, there's no need to quote any annotations anyway) - In a stub file it won't fail, but you shouldn't ever use quoted annotations in a stub file anyway, and we have PYI020 to tell you off about that if you do
So I don't think it would be worth the added complexity
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.
All LGTM other than https://github.com/astral-sh/ruff/pull/15342/files#r1906988995.
Thanks so much @sbrugman for this improvement. Changes like this make me really happy. It's still so cool that Ruff can provide sophisticated autofixes like this 😃
…e-union-members` (`PYI016`) (#15342)
…e-union-members` (`PYI016`) (#15342)
Summary
Stabilizes the fix extension introduced in #14270
Test Plan
There are no open issues related to
PYI016
fixes. The most recent issue was fixed on Nov 25. There are also no open issues with the rule itself.I reviewed the ecosystem changes and they look good.