Closed
Description
Bug Report
It seems you can't take a union of unions using the new Type Union Operator.
To Reproduce
- Run Mypy on this file:
from typing import TypeAlias, Union
class Dog:
pass
class Cat:
pass
class Salmon:
pass
class Trout:
pass
Mammal: TypeAlias = Dog | Cat
Fish: TypeAlias = Salmon | Trout
Animal: TypeAlias = Mammal | Fish # type error!!
Animal2: TypeAlias = Union[Mammal, Fish] # no type error, as expected
Expected Behavior
In PEP-0604, it says "The existing typing.Union
and |
syntax should be equivalent.". Therefore, I assumed the last 2 lines above would both behave similarly.
Actual Behavior
Mypy throws type error:
error: Unsupported left operand type for | ("object")
Your Environment
- Mypy version used: 0.931
- Mypy command-line flags: <no flags>
- Mypy configuration options from
mypy.ini
(and other config files): <no config> - Python version used: 3.10.2
- Operating system and version: Ubuntu 20.04