-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Closed
Copy link
Labels
bugSomething isn't workingSomething isn't working
Description
Hi! 👋
The UP007 rule is not catching the scenarios where a type alias is defined without the TypeAlias annotation, which is likely to happen when upgrading from py39 to py310.
test.py
Minimal code snipped that reproduces the bug:
from typing import Literal, Optional, TypeAlias, Union
YesNo = Literal["yes", "no"]
OptionalYesNo = Optional[YesNo]
OptionalBlankYesNo = Union[OptionalYesNo, Literal[""]]
OptionalYesNoAlias: TypeAlias = Optional[YesNo]
OptionalBlankYesNoAlias: TypeAlias = Union[OptionalYesNo, Literal[""]]
Ruff output
The command I've invoked: ruff --isolated --select UP --target-version py310 test.py
test.py:6:33: UP007 [*] Use `X | Y` for type annotations
test.py:7:38: UP007 [*] Use `X | Y` for type annotations
Found 2 errors.
[*] 2 potentially fixable with the --fix option.
I was expecting UP007 to have reported lines 4 and 5 too. When using --fix I was expecting the fixed code to be:
from typing import Literal, TypeAlias
YesNo = Literal["yes", "no"]
OptionalYesNo = YesNo | None
OptionalBlankYesNo = OptionalYesNo | Literal[""]
OptionalYesNoAlias: TypeAlias = YesNo | None
OptionalBlankYesNoAlias: TypeAlias = OptionalYesNo | Literal[""]
ruff --version
ruff 0.0.262
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working