Skip to content

False negative: Tuple index out of range #10317

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

Closed
goodspark opened this issue Apr 13, 2021 · 1 comment
Closed

False negative: Tuple index out of range #10317

goodspark opened this issue Apr 13, 2021 · 1 comment
Labels
bug mypy got something wrong

Comments

@goodspark
Copy link

Bug Report

Getting a false negative on tuple indices and lengths.

To Reproduce

from typing import Tuple, Union

def zxc(x: Union[Tuple[str], Tuple[str, int]]) -> None:
    if len(x) == 1:
        print(x[0])
    elif len(x) == 2:
        print(x[0], x[1])  # line 7
mypy mypytest.py

Expected Behavior

Expected mypy to pass. As far as I can tell, the types are correct.

Actual Behavior

Mypy fails with:

mypytest.py:7: error: Tuple index out of range
Found 1 error in 1 file (checked 1 source file)

Your Environment

  • Mypy version used: 0.812
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.8.5
  • Operating system and version: Ubuntu 20.04
@goodspark goodspark added the bug mypy got something wrong label Apr 13, 2021
@hauntsaninja
Copy link
Collaborator

Duplicate of #9171 , #1178 and others (also this is a false positive :-) )

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