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 variable escapes in application of higher-order function to a generic function #1506

Closed
rwbarton opened this issue May 7, 2016 · 2 comments
Labels
bug mypy got something wrong priority-1-normal

Comments

@rwbarton
Copy link
Contributor

rwbarton commented May 7, 2016

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

The type of y is not allowed to contain an unbound type variable. There should have been an error Need type annotation for variable on the assignment to y.

(With apply having type def apply(f: Callable[[int], int]) -> S, mypy does give such an error.)

@rwbarton rwbarton self-assigned this May 7, 2016
@rwbarton rwbarton added the bug mypy got something wrong label May 7, 2016
@rwbarton rwbarton changed the title type variable escapes in application of higher-order function type variable escapes in application of higher-order function to a generic function May 8, 2016
@rwbarton
Copy link
Contributor Author

rwbarton commented May 8, 2016

Also, even when the input program has a type error, mypy should still not produce ill-formed types like S-1` here. That way we can run mypy in a mode with extra consistency checks on the test suite, which is full of intentional type errors, to find more bugs like this one.

@erictraut
Copy link

Mypy is arguably doing the right thing in this case. The code sample contains a malformed generic function g that returns a generic S but doesn't use S in the types of any input parameters. Mypy correctly reports this error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong priority-1-normal
Projects
None yet
Development

No branches or pull requests

5 participants