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
Union types are valid types, just like any other types. That's at least my expectation. However, you cannot currently type alias union types.
For example,
X: TypeAlias=int|str# line 3deff(b: bool) ->X: # line 6ifb:
return3else:
return"three"
Mypy will issue the following errors:
typealias_test.py:3: error: Variable "typing.TypeAlias" is not valid as a type
typealias_test.py:6: error: Variable "typealias_test.X" is not valid as a type
To Reproduce
Create a type alias for a union type, using either typing.Union or the 3.10 vert bar syntax.
You can explicitly declare the type alias implicitly or explicitly with typing.TypeAlias.
Run mypy check. Union type aliases are not recognized as type by mypy.
Expected Behavior
Union types should be treated as just any other types.
Actual Behavior
Union types cannot be type-aliased in the current impl of mypy.
Your Environment
Mypy version used: 0.910
Mypy command-line flags: none
Mypy configuration options from mypy.ini (and other config files): none
Python version used: 3.10.0
Operating system and version: Ubuntu 20.04.
The text was updated successfully, but these errors were encountered:
It seems slightly more complicated than I initially thought. Type alias X = Union[T1, T2] works. However, X: TypeAlias = Union[T1, T2] does not work. For the 3.10 syntax, neither X = T1 | T2 nor X: TypeAlias = T1 | T2 work.
Bug Report
Union types are valid types, just like any other types. That's at least my expectation. However, you cannot currently type alias union types.
For example,
Mypy will issue the following errors:
To Reproduce
typing.Union
or the 3.10 vert bar syntax.Expected Behavior
Union types should be treated as just any other types.
Actual Behavior
Union types cannot be type-aliased in the current impl of mypy.
Your Environment
mypy.ini
(and other config files): noneThe text was updated successfully, but these errors were encountered: