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

functools.partial not well supported #2967

Closed
rhettinger opened this issue Mar 6, 2017 · 3 comments
Closed

functools.partial not well supported #2967

rhettinger opened this issue Mar 6, 2017 · 3 comments

Comments

@rhettinger
Copy link

Given this code:

from typing import Tuple
from math import hypot
from functools import partial

def dist(p: Tuple[float, float], q: Tuple[float, float]) -> float:
    px, py = p
    qx, qy = q
    return hypot(px - qx, py - qy)

base = (1.9, 7.5)
targets = [(3,7), (2,6), (1,8), (0,7)]

def make_fixed_dist(q):
    def fixed_dist(p):
	return dist(p, q)
    return fixed_dist

print( min(targets, key=make_fixed_dist(base)) )
print( min(targets, key=partial(dist, base)) )

mypy cheerfully accepts the closure but chokes on the equivalent partial:

$ mypy tmp.py
tmp.py:19: error: No overload variant of "min" matches argument types [builtins.list[Tuple[builtins.int, builtins.int]], functools.partial[builtins.float*]]
@JukkaL
Copy link
Collaborator

JukkaL commented Mar 6, 2017

Mypy doesn't fully support partial (#1484), and because of the way the stub for partial is written, you also get bitten by #797.

@socketpair
Copy link

socketpair commented Mar 28, 2020

def test(x: str, y: int):
    pass

z1 = partial(test, 42)
z2 = partial(test, 42, 6.7)

It also does not generate any warnings.

@AlexWaygood
Copy link
Member

The original snippet provided by @rhettinger no longer causes mypy to emit an error. There are still issues with mypy's support for functools.partial, but #1484 is the better place to discuss those.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants