mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 22:01:18 +00:00
[flake8-pyi
] - fix dropped exprs in PYI030
autofix (#13727)
This commit is contained in:
parent
3209953276
commit
46bc69d1d4
3 changed files with 25 additions and 0 deletions
|
@ -87,3 +87,7 @@ field24: typing.Union[Literal[1], typing.Union[Literal[2], typing.Union[Literal[
|
||||||
|
|
||||||
# Should use the first literal subscript attribute when fixing
|
# Should use the first literal subscript attribute when fixing
|
||||||
field25: typing.Union[typing_extensions.Literal[1], typing.Union[Literal[2], typing.Union[Literal[3], Literal[4]]], str] # Error
|
field25: typing.Union[typing_extensions.Literal[1], typing.Union[Literal[2], typing.Union[Literal[3], Literal[4]]], str] # Error
|
||||||
|
|
||||||
|
from typing import IO, Literal
|
||||||
|
|
||||||
|
InlineOption = Literal["a"] | Literal["b"] | IO[str]
|
||||||
|
|
|
@ -80,6 +80,8 @@ pub(crate) fn unnecessary_literal_union<'a>(checker: &mut Checker, expr: &'a Exp
|
||||||
} else {
|
} else {
|
||||||
literal_exprs.push(slice);
|
literal_exprs.push(slice);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
other_exprs.push(expr);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
other_exprs.push(expr);
|
other_exprs.push(expr);
|
||||||
|
|
|
@ -517,6 +517,8 @@ PYI030.py:89:10: PYI030 [*] Multiple literal members in a union. Use a single li
|
||||||
88 | # Should use the first literal subscript attribute when fixing
|
88 | # Should use the first literal subscript attribute when fixing
|
||||||
89 | field25: typing.Union[typing_extensions.Literal[1], typing.Union[Literal[2], typing.Union[Literal[3], Literal[4]]], str] # Error
|
89 | field25: typing.Union[typing_extensions.Literal[1], typing.Union[Literal[2], typing.Union[Literal[3], Literal[4]]], str] # Error
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYI030
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYI030
|
||||||
|
90 |
|
||||||
|
91 | from typing import IO, Literal
|
||||||
|
|
|
|
||||||
= help: Replace with a single `Literal`
|
= help: Replace with a single `Literal`
|
||||||
|
|
||||||
|
@ -526,5 +528,22 @@ PYI030.py:89:10: PYI030 [*] Multiple literal members in a union. Use a single li
|
||||||
88 88 | # Should use the first literal subscript attribute when fixing
|
88 88 | # Should use the first literal subscript attribute when fixing
|
||||||
89 |-field25: typing.Union[typing_extensions.Literal[1], typing.Union[Literal[2], typing.Union[Literal[3], Literal[4]]], str] # Error
|
89 |-field25: typing.Union[typing_extensions.Literal[1], typing.Union[Literal[2], typing.Union[Literal[3], Literal[4]]], str] # Error
|
||||||
89 |+field25: typing.Union[typing_extensions.Literal[1, 2, 3, 4], str] # Error
|
89 |+field25: typing.Union[typing_extensions.Literal[1, 2, 3, 4], str] # Error
|
||||||
|
90 90 |
|
||||||
|
91 91 | from typing import IO, Literal
|
||||||
|
92 92 |
|
||||||
|
|
||||||
|
PYI030.py:93:16: PYI030 [*] Multiple literal members in a union. Use a single literal, e.g. `Literal["a", "b"]`
|
||||||
|
|
|
||||||
|
91 | from typing import IO, Literal
|
||||||
|
92 |
|
||||||
|
93 | InlineOption = Literal["a"] | Literal["b"] | IO[str]
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ PYI030
|
||||||
|
|
|
||||||
|
= help: Replace with a single `Literal`
|
||||||
|
|
||||||
|
ℹ Safe fix
|
||||||
|
90 90 |
|
||||||
|
91 91 | from typing import IO, Literal
|
||||||
|
92 92 |
|
||||||
|
93 |-InlineOption = Literal["a"] | Literal["b"] | IO[str]
|
||||||
|
93 |+InlineOption = Literal["a", "b"] | IO[str]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue