Skip to content

Commit ad09309

Browse files
committed
Add test demonstrating functools.partial bug
1 parent 82d0425 commit ad09309

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

test-data/unit/check-functools.test

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,30 @@ reveal_type(p3(2)) # N: Revealed type is "builtins.int"
249249
reveal_type(p3("a")) # N: Revealed type is "builtins.str"
250250
[builtins fixtures/dict.pyi]
251251

252+
[case testFunctoolsPartialGenericType]
253+
from typing import Type, TypeVar
254+
import functools
255+
256+
T = TypeVar("T", int, str)
257+
258+
def foo(a: int, b: str, t: Type[T]) -> T: ...
259+
260+
p1 = functools.partial(foo, 1, 2) # E: Argument 2 to "foo" has incompatible type "int"; expected "str"
261+
p2 = functools.partial(foo, "hello", "world") # E: Argument 1 to "foo" has incompatible type "str"; expected "int"
262+
p3 = functools.partial(foo, 1, "hello")
263+
264+
reveal_type(p3) # N: Revealed type is "functools.partial[builtins.int]" # should still be generic
265+
reveal_type(p3(int)) # N: Revealed type is "builtins.int"
266+
reveal_type(p3(str)) # N: Revealed type is "builtins.int" \
267+
# E: Argument 1 to "foo" has incompatible type "Type[str]"; expected "Type[int]"
268+
reveal_type(p3(list)) # N: Revealed type is "builtins.int" \
269+
# E: Argument 1 to "foo" has incompatible type "Type[List[Any]]"; expected "Type[int]"
270+
271+
272+
273+
274+
[builtins fixtures/tuple.pyi]
275+
252276
[case testFunctoolsPartialCallable]
253277
from typing import Callable
254278
import functools

0 commit comments

Comments
 (0)