You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is because Ruff can't be sure here that Q is a type alias, so it doesn't know whether to analyse it as a type expression or a value expression. If you explicitly annotate it with typing.TypeAlias or typing_extensions.TypeAlias, the diagnostic is emitted as expected:
fromtypingimportTypeAliasQ: TypeAlias=int|int
Same if you use a type statement on Python 3.12 or newer:
From a human's perspective, it's obvious that X = int | int is an attempt to create a type alias. But from a static-analysis tool's perspective, how can it unambiguously differentiate X = int | int from Y = 42 | 56 (which is not a type alias, just a normal value being assigned to a variable)?
This would be easier for Ruff if it had better type inference. But even for type checkers, differentiating type aliases from other assignments isn't easy. If it were easy, there wouldn't be any need for typing.TypeAlias at all, and PEP 613 would never have been written :-)
Description
Not flagged, should raise PYI016
ruff 0.9.3
The text was updated successfully, but these errors were encountered: