mypy
mypy copied to clipboard
(🐞) generic `__init__` causes invalid error message "Type application has too few types"
from typing import Generic, TypeVar, _T as T
U = TypeVar("U")
class A(Generic[T]):
def __init__(self, u: U):
...
a: A[int] # okay
a = A[int]("asdf") # error: Type application has too few types (2 expected) [misc]
- Similar to #13437
This affects SQLAlchemy with InstrumentedAttribute. Weirdly, you don't even need to instantiate it, simply using the generic class (outside of an annotation) causes the error:
from sqlalchemy.orm import InstrumentedAttribute
foo: InstrumentedAttribute[Any] # This is fine
foo = InstrumentedAttribute[Any] # error: Type application has too few types (2 expected) [misc]