mypy
mypy copied to clipboard
mypy tries to infer the type parameters of a generic class even if they are explicitly given
Bug Report
mypy tries to infer the type parameters of a generic class even if they are explicitly given.
To Reproduce
from typing import overload
class Frobnicator[T]: # Using a TypeVar gives identical results
@overload
def __init__(self, param: T) -> None: ...
@overload # Removing `param` in this case gives identical results
def __init__(self: 'Frobnicator[None]', param: None = None) -> None: ...
def __init__(self, param: T | None = None) -> None:
...
Expected Behavior
I expect the following to produce a "missing argument" error (like Pyright 1.1.384 does).
f = Frobnicator[int]()
Actual Behavior
reveal_type(f) shows Frobnicator[None]
Your Environment
The behavior is identical for mypy v1.11.1, v1.11.2 and the master branch, with both Python 3.12 and 3.13. I tried it on my local Arch + pyenv based setup and, using TypeVar, in https://mypy-play.net