-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
new union syntax doesn't work on Literal
s
#11426
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
Labels
bug
mypy got something wrong
topic-pep-604
PEP 604 (union | operator)
topic-type-alias
TypeAlias and other type alias issues
Comments
This also happens without from typing import Literal
Foo = Literal[1, 2]
Bar = Foo | Literal[3]
# error: Invalid type alias: expression is not a valid type
# error: Unsupported left operand type for | ("object") Will fix it right now, thanks! |
On python3.10 it generates a single error:
|
On 3.9 without the import the error is correct since |
JukkaL
added a commit
that referenced
this issue
Nov 7, 2022
Fix Python 3.10 `|` union syntax in type aliases, when one of the operands is a type alias or a type with an overloaded `__init__`. We can now infer `typing._SpecialForm` for type aliases in a runtime context. Also create a bunch of minimal test-only stubs for stdlib modules to fix some test failures caused by the missing `typing._SpecialForm` in the default test stubs. This is generally what we want in any case, since using typeshed stubs with minimal builtins/typing stubs can result in unpredictable behavior and slow tests. Fixes #12368. Fixes #12005. Fixes #11426.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
bug
mypy got something wrong
topic-pep-604
PEP 604 (union | operator)
topic-type-alias
TypeAlias and other type alias issues
https://mypy-play.net/?mypy=latest&python=3.10&gist=3a429dfa3e9e3b692aac25887027ab69
The text was updated successfully, but these errors were encountered: