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

type not inferred in application of higher-order function to a generic function #1507

Closed
rwbarton opened this issue May 8, 2016 · 2 comments
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-1-normal topic-type-variables

Comments

@rwbarton
Copy link
Contributor

rwbarton commented May 8, 2016

from typing import TypeVar, Callable
S = TypeVar('S')
def apply(f: Callable[[int], S]) -> S: pass
def g(x: S) -> S: pass
y = apply(g) # E: Argument 1 to "apply" has incompatible type Callable[[S], S]; expected Callable[[int], S]
reveal_type(y) # E: Revealed type is 'S`-1'

The call to apply should type check, with both types S and the type of y being int.

I encountered this sort of situation in mypy/codec/pytokenize.py in the lines

tokenprog, pseudoprog, single3prog, double3prog = map(
    re.compile, (Token, PseudoToken, Single3, Double3))

#1471 was an attempt to fix this, but since it fixes this case but not #1506, I'm filing these as two related but distinct issues.

@davidhalter
Copy link

davidhalter commented Jan 21, 2024

This is working now. So I feel like this issue should be closed.

See https://mypy-play.net/?mypy=latest&python=3.12&gist=2265ae341b2994f28577afc8788c0879

@hauntsaninja
Copy link
Collaborator

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in 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

6 participants