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

VarArg not working with builtin functions like max() or sum() #6498

Closed
GoldsteinE opened this issue Mar 1, 2019 · 1 comment
Closed

VarArg not working with builtin functions like max() or sum() #6498

GoldsteinE opened this issue Mar 1, 2019 · 1 comment

Comments

@GoldsteinE
Copy link

Simple example:

from typing import Callable
from mypy_extensions import VarArg


f: Callable[[VarArg(float)], float] = max

I can use max() as a function of floats with variadic args, but mypy gives me an error:

main.py:5: error: Incompatible types in assignment (expression has type overloaded function, variable has type "Callable[[VarArg(float)], float]")

I have mypy v0.670, Python 3.7.2. It's reproducible on mypy-play: https://mypy-play.net/?gist=df78cea368c8240fa82c63d5546f8aae

@ilevkivskyi
Copy link
Member

Mypy has troubles figuring subtyping between callables and overloads, see e.g. #495, but in this case mypy is right. A function annotated as in your code supports calls like f() and f(42), but max fails, since there are at least two required arguments. So you should write:

f: Callable[[float, float, VarArg(float)], float] = max

This passes mypy.

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

2 participants