Open bjoernpollex opened 1 week ago
From more investigation, the specific problem is that a when a variable of type type[C]
is called, it's constructor type variables reject all types except Any
. (classmethod
gives cls
the type type[C]
.)
# --strict
from typing import TypeVar
from collections.abc import Callable
T = TypeVar("T")
class C:
def __init__(self, arg1: T, arg2: T):
pass
C(1, 1) # okay
bar: Callable[[object, object], C] = C
bar(1, 1) # okay
foo: type[C]
foo(1, 1) # error
# main.py:17: error: Argument 1 to "C" has incompatible type "int"; expected "T" [arg-type]
Bug Report
When calling a generic
__init__
from a generic@classmethod
on a class that is itself not generic,mypy
reports incompatible types.To Reproduce
Expected Behavior
mypy
reports no errors.Actual Behavior
Your Environment
mypy 1.11.2 (compiled: yes)
mypy.ini
(and other config files): N/APython 3.11.7