[flake8-pyi]: Stabilize: Provide more automated fixes for duplicate-union-members (PYI016)#15342
[flake8-pyi]: Stabilize: Provide more automated fixes for duplicate-union-members (PYI016)#15342MichaReiser merged 2 commits intoruff-0.9from
flake8-pyi]: Stabilize: Provide more automated fixes for duplicate-union-members (PYI016)#15342Conversation
…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.
It seems like #14270 incorrectly removed the fix for non-preview 🤷 So, technically, this PR makes the rule fixable again
|
| code | total | + violation | - violation | + fix | - fix |
|---|---|---|---|---|---|
| PYI016 | 10 | 0 | 0 | 10 | 0 |
Linter (preview)
✅ ecosystem check detected no linter changes.
| 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.
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
TypeErrorunless you havefrom __future__ import annotationsat 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
AlexWaygood
left a comment
There was a problem hiding this comment.
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
PYI016fixes. 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.