Skip to content

functools.partial false negative with higher order functions #17461

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

Open
hauntsaninja opened this issue Jul 1, 2024 · 0 comments
Open

functools.partial false negative with higher order functions #17461

hauntsaninja opened this issue Jul 1, 2024 · 0 comments
Labels
bug mypy got something wrong

Comments

@hauntsaninja
Copy link
Collaborator

See #17425 , in particular this comment #17425 (comment) from ilevkivskyi

[case testFunctoolsPartialHigherOrder]
from functools import partial
from typing import Callable

def fn(a: int, b: str, c: bytes) -> int: ...

def callback1(fn: Callable[[str, bytes], int]) -> None: ...
def callback2(fn: Callable[[str, int], int]) -> None: ...

callback1(partial(fn, 1))
# TODO: false negative
callback2(partial(fn, 1))
[builtins fixtures/tuple.pyi]
@hauntsaninja hauntsaninja added the bug mypy got something wrong label Jul 1, 2024
JukkaL pushed a commit that referenced this issue Jun 5, 2025
Fixes #18953. Fixes #15215. Refs #17461.

When the function passed to `partial` is generic and has generic params
in the return type, we must erase them, otherwise they become orphan and
cannot be used later. This only applies to `partial[...]` generic param
and not to the underlying "exact" callable stored internally as the
latter remains generic.

The ultimate fix would be to implement #17620 so that we stop caring
about `partial[...]` generic param, but this should improve usability
(but causes false negatives).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

1 participant