Skip to content

Add test demonstrating functools.partial bug #17297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions test-data/unit/check-functools.test
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,30 @@ reveal_type(p3(2)) # N: Revealed type is "builtins.int"
reveal_type(p3("a")) # N: Revealed type is "builtins.str"
[builtins fixtures/dict.pyi]

[case testFunctoolsPartialGenericType]
from typing import Type, TypeVar
import functools

T = TypeVar("T", int, str)

def foo(a: int, b: str, t: Type[T]) -> T: ...

p1 = functools.partial(foo, 1, 2) # E: Argument 2 to "foo" has incompatible type "int"; expected "str"
p2 = functools.partial(foo, "hello", "world") # E: Argument 1 to "foo" has incompatible type "str"; expected "int"
p3 = functools.partial(foo, 1, "hello")

reveal_type(p3) # N: Revealed type is "functools.partial[builtins.int]" # should still be generic
reveal_type(p3(int)) # N: Revealed type is "builtins.int"
reveal_type(p3(str)) # N: Revealed type is "builtins.int" \
# E: Argument 1 to "foo" has incompatible type "Type[str]"; expected "Type[int]"
reveal_type(p3(list)) # N: Revealed type is "builtins.int" \
# E: Argument 1 to "foo" has incompatible type "Type[List[Any]]"; expected "Type[int]"




[builtins fixtures/tuple.pyi]

[case testFunctoolsPartialCallable]
from typing import Callable
import functools
Expand Down
Loading