@@ -303,12 +303,12 @@ p(1) # E: Argument 1 to "A" has incompatible type "int"; expected "str"
303303p(z=1) # E: Unexpected keyword argument "z" for "A"
304304
305305def main(t: Type[A]) -> None:
306- p = functools.partial(t, 1) # E: "Type[A]" not callable
306+ p = functools.partial(t, 1)
307307 reveal_type(p) # N: Revealed type is "functools.partial[__main__.A]"
308308
309309 p("a") # OK
310- p(1) # False negative
311- p(z=1) # False negative
310+ p(1) # E: Argument 1 to "A" has incompatible type "int"; expected "str"
311+ p(z=1) # E: Unexpected keyword argument "z" for "A"
312312
313313[builtins fixtures/dict.pyi]
314314
@@ -346,3 +346,29 @@ reveal_type(functools.partial(fn3, 2)()) # E: "str" not callable \
346346 # N: Revealed type is "builtins.int" \
347347 # E: Argument 1 to "partial" has incompatible type "Union[Callable[[int], int], str]"; expected "Callable[..., int]"
348348[builtins fixtures/tuple.pyi]
349+
350+ [case testFunctoolsPartialTypeObject]
351+ import functools
352+ from typing import Type, Generic, TypeVar
353+
354+ class A:
355+ def __init__(self, val: int) -> None: ...
356+
357+ cls1: Type[A]
358+ reveal_type(functools.partial(cls1, 2)()) # N: Revealed type is "__main__.A"
359+ functools.partial(cls1, "asdf") # E: Argument 1 to "A" has incompatible type "str"; expected "int"
360+
361+ T = TypeVar("T")
362+ class B(Generic[T]):
363+ def __init__(self, val: T) -> None: ...
364+
365+ cls2: Type[B[int]]
366+ reveal_type(functools.partial(cls2, 2)()) # N: Revealed type is "__main__.B[builtins.int]"
367+ functools.partial(cls2, "asdf") # E: Argument 1 to "B" has incompatible type "str"; expected "int"
368+
369+ def foo(cls3: Type[B[T]]):
370+ reveal_type(functools.partial(cls3, "asdf")) # N: Revealed type is "functools.partial[__main__.B[T`-1]]" \
371+ # E: Argument 1 to "B" has incompatible type "str"; expected "T"
372+ reveal_type(functools.partial(cls3, 2)()) # N: Revealed type is "__main__.B[T`-1]" \
373+ # E: Argument 1 to "B" has incompatible type "int"; expected "T"
374+ [builtins fixtures/tuple.pyi]
0 commit comments