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

Interference between two different type variables #4425

Open
JukkaL opened this issue Jan 3, 2018 · 1 comment
Open

Interference between two different type variables #4425

JukkaL opened this issue Jan 3, 2018 · 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 Jan 3, 2018

Mypy rejects this fragment, apparently because the type variables AnyStr and X interfere with each other:

from typing import TypeVar, Any, Callable, AnyStr

F = TypeVar('F', bound=Callable)

def on_exception_return(to_return):
    # type: (Any) -> Callable[[F], F]
    pass

@on_exception_return(False)
def is_on(feature_name):
    # type: (AnyStr) -> bool
    return True

class A: pass
class B: pass

X = TypeVar('X', A, B)

def f(x: X) -> None:
    is_on('')

Here's the output I get:

t.py:20: error: Argument 1 to "is_on" has incompatible type "str"; expected "A"
t.py:20: error: Argument 1 to "is_on" has incompatible type "str"; expected "B"

The expected behavior is clean output.

We've already fixed a bunch of similar issues.

@ilevkivskyi
Copy link
Member

IIUC having the decorator is important to trigger this. So this seems to be closely related to #1317, in particular to the example in #1317 (comment).

@ilevkivskyi ilevkivskyi added bug mypy got something wrong priority-1-normal false-positive mypy gave an error on correct code labels Aug 15, 2018
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

3 participants