-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
"Invalid type" error when creating a synonym for Optional[int] #1637
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
Comments
IIRC global assignments are only remembered as type aliases when they contain certain things. Maybe Optional isn't in the list of things it looks for, while Union is? (I've occasionally had a similar issue but always just worked around it.) |
Yep that's exactly it. PR incoming... |
Actually this turns out to be more subtle than expected because of the way that |
Wait, that plan only makes sense if we are getting rid of non-strict optional checking, which probably won't happen that soon. I managed to get the tests passing again with some simple changes but I don't entirely understand the intent of the old code, so hopefully @JukkaL can take a quick look. |
Fixed by 2050d80. |
I don't think this is fixed, both the above and the snippet below fail with mypy 0.501 on Python 3.5.2, as discussed there is no error with
|
Confirmed, although I am not sure this is the original issue. In fact this has nothing to do with A = Union[int]
x: A The reason is how aliases are analyzed, there is a logical flaw in code, it naively expects that if alias is an Sorry, I don't have time to fix this right now, although the fix should be quite simple. |
Please open a new issue since Ivan says it's not the same issue. |
produces an error
A type synonym for
Union[str, int]
works fine.The text was updated successfully, but these errors were encountered: