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

Tuples that differ only in length are indistinguishable (mypy 0.790) #9747

Closed
kntroh opened this issue Nov 23, 2020 · 1 comment
Closed

Tuples that differ only in length are indistinguishable (mypy 0.790) #9747

kntroh opened this issue Nov 23, 2020 · 1 comment
Labels
bug mypy got something wrong

Comments

@kntroh
Copy link

kntroh commented Nov 23, 2020

Bug Report

from typing import *

TT = TypeVar("TT", Tuple[int, int], Tuple[int, int, int, int])

def func(tt: TT) -> TT:
    if len(tt) == 2:
        tt2 = (tt[0], tt[1])
        return tt2
    elif len(tt) == 4:
        tt4 = (tt[0], tt[1], tt[2], tt[3])
        return tt4
    assert False

print(func((0, 1)))
print(func((0, 1, 2, 3)))

Analysis for this code causes the three errors (mypy 0.790):

$ mypy mypytest.py
mypytest.py:8: error: Incompatible return value type (got "Tuple[int, int]", expected "Tuple[int, int, int, int]")
mypytest.py:10: error: Tuple index out of range
mypytest.py:11: error: Incompatible return value type (got "Tuple[int, int, Any, Any]", expected "Tuple[int, int]")
Found 3 errors in 1 file (checked 1 source file)

I think this is a glitch, but is there a technical reason for not being able to distinguish between these two types of tuples?

@kntroh kntroh added the bug mypy got something wrong label Nov 23, 2020
@hauntsaninja
Copy link
Collaborator

Duplicate of #9171 , #1178 and others

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

No branches or pull requests

2 participants