Skip to content

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

Closed
@AlexWaygood

Description

@AlexWaygood

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)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions