Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Generic function as first argument to map fails #3193

Closed
JukkaL opened this issue Apr 19, 2017 · 1 comment
Closed

Generic function as first argument to map fails #3193

JukkaL opened this issue Apr 19, 2017 · 1 comment
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-1-normal topic-type-variables

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Apr 19, 2017

From python/typeshed#1178:

map(tuple, [ [2, 3] ]) throws

error: Argument 1 to "map" has incompatible type Tuple[_T_co, ...]; expected Callable[[List[int]], Tuple[_T_co, ...]]

However, this is valid python code.

Here's a more self-contained example that reproduces the problem:

from typing import Callable, TypeVar

T = TypeVar('T')
S = TypeVar('S')

def f(fn: Callable[[T], S], x: T) -> None: pass
def g(x: T) -> T: pass

f(g, 1)  # Argument 1 to "f" has incompatible type Callable[[T], T]; expected Callable[[int], T]
@ilevkivskyi
Copy link
Member

I think this is just a duplicate of #1317, passing one generic callable as an argument to another generic callable causes type variables leaking.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-1-normal topic-type-variables
Projects
None yet
Development

No branches or pull requests

2 participants