Description
Bug Report
Python 3.10 new Union syntax doesn't work in a scenario old syntax did when involved with generic type aliases.
To Reproduce
Create the following definitions:
_ResponseType = TypeVar("_ResponseType")
SyncFunc: TypeAlias = Callable[..., _ResponseType]
Coro: TypeAlias = Callable[..., Coroutine[Any, Any, _ResponseType]]
SyncFuncOrCoro: TypeAlias = Coro[_ResponseType] | SyncFunc[_ResponseType]
Expected Behavior
Should work without errors, like it does when using old Union syntax:
_ResponseType = TypeVar("_ResponseType")
SyncFunc: TypeAlias = Callable[..., _ResponseType]
Coro: TypeAlias = Callable[..., Coroutine[Any, Any, _ResponseType]]
SyncFuncOrCoro: TypeAlias = Union[Coro[_ResponseType], SyncFunc[_ResponseType]]
Actual Behavior
I receive mypy error "Type application is only supported for generic classes".
Your Environment
- Mypy version used: 0.931
- Mypy command-line flags: N/A
- Python version used: 3.10.2
- Operating system and version: Windows 11
- Mypy configuration options from
mypy.ini
(and other config files):
I'm using pretty strict mypy settings:
[mypy]
follow_imports = normal
ignore_errors = false
implicit_reexport = false
warn_redundant_casts = True
warn_unused_ignores = True
disallow_any_generics = True
disallow_untyped_defs = True
check_untyped_defs = True
allow_redefinition = false
local_partial_types = True
strict_optional = true
strict_equality = true
warn_unused_configs = true
warn_unreachable = true
warn_no_return = true
no_implicit_optional = true