[flake8-pyi] Avoid rewriting invalid type expressions in unnecessary-type-union (PYI055) (#14660)
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / benchmarks (push) Blocked by required conditions

This commit is contained in:
Simon Brugman 2024-11-28 19:30:50 +01:00 committed by GitHub
parent 224fe75a76
commit abb3c6ea95
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 92 additions and 68 deletions

View file

@ -5,10 +5,10 @@ s: builtins.type[int] | builtins.type[str] | builtins.type[complex]
t: type[int] | type[str] | type[float]
u: builtins.type[int] | type[str] | builtins.type[complex]
v: Union[type[float], type[complex]]
w: Union[type[float, int], type[complex]]
x: Union[Union[type[float, int], type[complex]]]
y: Union[Union[Union[type[float, int], type[complex]]]]
z: Union[type[complex], Union[Union[type[float, int]]]]
w: Union[type[float | int], type[complex]]
x: Union[Union[type[Union[float, int]], type[complex]]]
y: Union[Union[Union[type[float | int], type[complex]]]]
z: Union[type[complex], Union[Union[type[Union[float, int]]]]]
def func(arg: type[int] | str | type[float]) -> None:
@ -16,8 +16,8 @@ def func(arg: type[int] | str | type[float]) -> None:
# OK
x: type[int, str, float]
y: builtins.type[int, str, complex]
x: type[int | str | float]
y: builtins.type[int | str | complex]
z: Union[float, complex]
@ -68,3 +68,11 @@ def convert_union(union: UnionType) -> _T | None:
Union[type[_T] | type[Converter[_T]] | str] | Converter[_T] | Callable[[str], _T], ... # PYI055
] = union.__args__
...
# `type[float, int]`` is not valid, use `type[float|int]` or `type[Union[float, int]]`
# OK for PYI055, should be covered by another check.
a: Union[type[float, int], type[complex]]
b: Union[Union[type[float, int], type[complex]]]
c: Union[Union[Union[type[float, int], type[complex]]]]
d: Union[type[complex], Union[Union[type[float, int]]]]

View file

@ -5,16 +5,16 @@ s: builtins.type[int] | builtins.type[str] | builtins.type[complex]
t: type[int] | type[str] | type[float]
u: builtins.type[int] | type[str] | builtins.type[complex]
v: Union[type[float], type[complex]]
w: Union[type[float, int], type[complex]]
x: Union[Union[type[float, int], type[complex]]]
y: Union[Union[Union[type[float, int], type[complex]]]]
z: Union[type[complex], Union[Union[type[float, int]]]]
w: Union[type[Union[float, int]], type[complex]]
x: Union[Union[type[Union[float, int]], type[complex]]]
y: Union[Union[Union[type[Union[float, int]], type[complex]]]]
z: Union[type[complex], Union[Union[type[Union[float, int]]]]]
def func(arg: type[int] | str | type[float]) -> None: ...
# OK
x: type[int, str, float]
y: builtins.type[int, str, complex]
x: type[int | str | float]
y: builtins.type[int | str | complex]
z: Union[float, complex]
def func(arg: type[int, float] | str) -> None: ...
@ -29,3 +29,10 @@ def func():
item3: Union[ # comment
type[requests_mock.Mocker], # another comment
type[httpretty], type[str]] = requests_mock.Mocker
# OK
w: Union[type[float, int], type[complex]]
x: Union[Union[type[float, int], type[complex]]]
y: Union[Union[Union[type[float, int], type[complex]]]]
z: Union[type[complex], Union[Union[type[float, int]]]]