mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 10:48:32 +00:00
[flake8-pyi
] Improve autofix for nested and mixed type unions unnecessary-type-union
(PYI055
) (#14272)
## Summary This PR improves the fix for `PYI055` to be able to handle nested and mixed type unions. It also marks the fix as unsafe when comments are present. <!-- What's the purpose of the change? What does it do, and why? --> ## Test Plan <!-- How was it tested? -->
This commit is contained in:
parent
2b6d66b793
commit
bd30701980
5 changed files with 236 additions and 135 deletions
|
@ -30,6 +30,9 @@ def func():
|
|||
# PYI055
|
||||
x: type[requests_mock.Mocker] | type[httpretty] | type[str] = requests_mock.Mocker
|
||||
y: Union[type[requests_mock.Mocker], type[httpretty], type[str]] = requests_mock.Mocker
|
||||
z: Union[ # comment
|
||||
type[requests_mock.Mocker], # another comment
|
||||
type[httpretty], type[str]] = requests_mock.Mocker
|
||||
|
||||
|
||||
def func():
|
||||
|
|
|
@ -16,10 +16,13 @@ z: Union[float, complex]
|
|||
|
||||
def func(arg: type[int, float] | str) -> None: ...
|
||||
|
||||
# OK
|
||||
# PYI055
|
||||
item: type[requests_mock.Mocker] | type[httpretty] = requests_mock.Mocker
|
||||
|
||||
def func():
|
||||
# PYI055
|
||||
item: type[requests_mock.Mocker] | type[httpretty] | type[str] = requests_mock.Mocker
|
||||
item2: Union[type[requests_mock.Mocker], type[httpretty], type[str]] = requests_mock.Mocker
|
||||
item3: Union[ # comment
|
||||
type[requests_mock.Mocker], # another comment
|
||||
type[httpretty], type[str]] = requests_mock.Mocker
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue