-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Removing ambiguity from the creation of a simple type alias #5779
Comments
There is already
I however don't want to rename it to just Also in my experience, the situations where people actually need an alias |
I wanted to chime in here from the perspective of string annotations - right now, it's hard for readers as well as type checkers to detect that Alias is a type in the below example:
Because of this, we have to over-approximate the set of possible type aliases in Pyre to include every assignment to a string that matches a known type. I think there's value in supporting some sort of explicit type alias syntax, this problem doesn't seem mypy-specific :) |
For the string problem there are two solutions/workarounds:
TBH I have never had this problem before, but yes this is another small reason in favor of having a more beautiful/explicit solution. |
It seems this issue will be solved by PEP 613 -- Explicit Type Aliases, mypy issue #9404? |
Yup! |
Currently assignments like these are somewhat ambiguous -- they can define a variable that refers to a type object or a type alias:
Currently the assignment creates a variable in function scope and a type alias elsewhere. This is pretty confusing -- see #5769 for an example.
There are a few things that could help:
X = TypeAlias(str)
that forces the creation of a type alias. If we report an invalid type due to a misinterpreted type alias, we can perhaps suggest usingTypeAlias(...)
.Type[foo]
variable annotation.This is only a problem with simple type aliases. Aliases like
X = List[int]
are always treated as type aliases.@ilevkivskyi Thoughts about this?
The text was updated successfully, but these errors were encountered: