Replies: 1 comment
-
There are no defined rules for determining whether an unannotated variable should be treated as a type alias. Pyright uses a bunch of heuristics. Changing these heuristics tends to be disruptive, so unless there's a compelling reason to touch that code, I leave it as is. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I've noticed that Pyright considers variables that don't have explicit type annotation to be type alias when being assigned
Any
value, for example:Here
bar
has this tooltip from Pyright:(type alias) bar: Any
. Which in turn results in this code being accepted:mypy raises this error:
Variable "test.bar" is not valid as a type [valid-type]
.Before Pyright 1.1.117
bar
was also a variable. That release has this change:It looks like we were supposed to get fewer type aliases and more just variables but this specific case was instead changed from variable to type alias? As evident by the error this is not consistent with mypy (or maybe they changed logic since 2021).
Was this intentional? If yes, why change from variable to implicit type alias?
P.S. I haven't encountered any problems from this behavior, just a confusing tooltip saying that my variable was type alias in this code:
Beta Was this translation helpful? Give feedback.
All reactions