GenericAlias not Callable, but it should be
Bug Report
The docs for GenericAlias explicitly state these objects are callable, giving the following example:
>>> t = list[str]
>>> t([1, 2, 3])
[1, 2, 3]
However the typeshed definition is not marked as such, and hence causes errors when type checking such cases.
In particular mypy erroneous reports: "GenericAlias" not callable when checking calls such as the above.
I initially reported this to typeshed, but they said it was too complex to fix there, so type checkers like mypy will need to special-case this.
Your Environment
- Mypy version used: 0.971
- Python version used: 3.10
- Operating system and version: Ubuntu 22.04
Actually, I can't reproduce: https://mypy-play.net/?mypy=latest&python=3.10&gist=aa1db479d5f97e6cd67fede0b7c543e1
You can reproduce it with something like this:
from types import GenericAlias
t: GenericAlias = list[int]
t([1, 2, 3])
But I'm not sure there's an actionable problem there.GenericAlias is essentially a runtime implementation artifact; mypy doesn't and needn't know that list[int] is a GenericAlias.
I think mypy is doing the right thing here. As Jelle explains, GenericAlias is an internal implementation detail. It is not meant to participate in the static type system. Recommend closing.