Skip to content
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

[1.11 Regression] partial plugin doesn't respect TypeVar bounds when deciding if something can be passed to partial #17646

Closed
AlexWaygood opened this issue Aug 5, 2024 · 3 comments · Fixed by #17660
Labels
bug mypy got something wrong topic-type-variables

Comments

@AlexWaygood
Copy link
Member

Bug Report

from typing import Callable, TypeVar
import functools

T = TypeVar("T", bound=Callable[[str, int], str])
S = TypeVar("S", bound=type[str])

def foo(f: T) -> T:
    g = functools.partial(f, "foo")  # error: "T" not callable  [misc]
    return f

def bar(f: S) -> S:
    g = functools.partial(f, "foo")  # error: "S" not callable  [misc]
    return f

https://mypy-play.net/?mypy=master&python=3.12&gist=93876fe629e5320a88349da7a9f65188

Mypy should understand both T and S to be callable due to the fact that the TypeVars have Callable and type as their respective upper bounds. We're hitting this in our attempt to upgrade mypy to 1.11.1 for Argument Clinic over at CPython in python/cpython#122550.

Cc. @hauntsaninja

Your Environment

  • Mypy version used: 1.12.0+dev.9d56820a63d5b47b53ff0ab6e96ce0951c774ae5 (compiled: no)
@AlexWaygood AlexWaygood added the bug mypy got something wrong label Aug 5, 2024
@AlexWaygood AlexWaygood changed the title partial plugin doesn't respect TypeVar bounds partial plugin doesn't respect TypeVar bounds when deciding if something can be passed to partial Aug 5, 2024
@AlexWaygood
Copy link
Member Author

#17659 notes that this also causes issues for Self (which is internally just a special kind of TypeVar)

@AlexWaygood AlexWaygood changed the title partial plugin doesn't respect TypeVar bounds when deciding if something can be passed to partial [1.11 Regression] partial plugin doesn't respect TypeVar bounds when deciding if something can be passed to partial Aug 10, 2024
hauntsaninja added a commit to hauntsaninja/mypy that referenced this issue Aug 10, 2024
@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Aug 10, 2024

I'm going to very disappointingly fix this in #17660

@AlexWaygood
Copy link
Member Author

That all makes sense; thanks for the explanation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-type-variables
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants