@@ -303,12 +303,12 @@ p(1) # E: Argument 1 to "A" has incompatible type "int"; expected "str"
303
303
p(z=1) # E: Unexpected keyword argument "z" for "A"
304
304
305
305
def main(t: Type[A]) -> None:
306
- p = functools.partial(t, 1) # E: "Type[A]" not callable
306
+ p = functools.partial(t, 1)
307
307
reveal_type(p) # N: Revealed type is "functools.partial[__main__.A]"
308
308
309
309
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"
312
312
313
313
[builtins fixtures/dict.pyi]
314
314
@@ -346,3 +346,29 @@ reveal_type(functools.partial(fn3, 2)()) # E: "str" not callable \
346
346
# N: Revealed type is "builtins.int" \
347
347
# E: Argument 1 to "partial" has incompatible type "Union[Callable[[int], int], str]"; expected "Callable[..., int]"
348
348
[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