Description
Bug Report
When validating manual type hints to the return of a call to functools.partial
, there has occurred a regression between the latest stable release (1.10.0) and the master branch, in that the git version asserts that the correct annotation should be partial[partial[T]]
, where T
is the type manually annotated for the functools.partial
call.
To Reproduce
TL;DR:
master branch: https://mypy-play.net/?mypy=master&python=3.12&gist=e45e31f06514aabe6a039dfc759e9a3b
1.10.0: https://mypy-play.net/?mypy=latest&python=3.12&gist=e45e31f06514aabe6a039dfc759e9a3b
Consider:
from functools import partial
from typing import Type, TypeVar
T = TypeVar("T")
def generic(string: str, integer: int, resulting_type: Type[T]) -> T:
if isinstance(string, resulting_type):
return string
elif isinstance(integer, resulting_type):
return integer
raise RuntimeError
Expected Behavior
For the below definition:
p: partial[str] = partial(generic, resulting_type=str)
The stable release does not generate any errors, as expected.
Actual Behavior
However, on the current git build, the following error message is displayed:
error: Incompatible types in assignment (expression has type "partial[partial[str]]", variable has type "partial[str]") [assignment]
error: Argument 1 to "generic" has incompatible type "type[str]"; expected "type[partial[str]]" [arg-type]
If the type annotation is changed to something nonsensical:
p: partial[bool] = partial(generic, resulting_type=str)
mypy now generates an error asserting the type of the expression is of type partial[partial[TYPE GIVEN]]
:
main.py:13: error: Incompatible types in assignment (expression has type "partial[partial[bool]]", variable has type "partial[bool]") [assignment]
main.py:13: error: Argument 1 to "generic" has incompatible type "type[str]"; expected "type[partial[bool]]" [arg-type]
Playground for this: https://mypy-play.net/?mypy=master&python=3.12&gist=8b38f943d002dc6ce084e8771251e78a
Your Environment
N/A, reproducible in mypy Playground environment.
Thank you for your hard work maintaining mypy!