mypy
mypy copied to clipboard
Generic Type[T] function argument rejected as base class
Bug Report
Since https://github.com/python/mypy/issues/5865 was fixed, the following code now type checks:
from typing import Any, Type
def f(typ: Type[Any]) -> Type[Any]:
class C(typ):
pass
return C
However if we make the superclass generic, it doesn't type check anymore which I would expect it to do.
To Reproduce
from typing import Type, TypeVar
T = TypeVar("T")
def f(typ: Type[T]) -> Type[T]:
class C(typ):
pass
return C
Actual Behavior
mypy_return_type.py:7: error: Variable "typ" is not valid as a type [valid-type]
mypy_return_type.py:7: note: See https://mypy.readthedocs.io/en/stable/common_issues.html#variables-vs-type-aliases
mypy_return_type.py:7: error: Invalid base class "typ" [misc]
Found 2 errors in 1 file (checked 1 source file)
Your Environment
- Mypy version used:
1.0.0+dev.e9f5858c44b61c2d02819940debe3c31d099f9d5 - Mypy command-line flags:
mypy mypy_return_type.py - Mypy configuration options from
mypy.ini(and other config files): None - Python version used:
3.10.9