Skip to content

bug in not-None inference for list items #9304

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
davidszotten opened this issue Aug 14, 2020 · 1 comment
Closed

bug in not-None inference for list items #9304

davidszotten opened this issue Aug 14, 2020 · 1 comment

Comments

@davidszotten
Copy link

Apologies if this is already reported, it's hard to know what words to look for

I think this is a bug in the "not None inference"

source:

from typing import List, Optional

idx = 0
lst: List[Optional[int]] = []

lst[0] is not None and reveal_type(lst[0])
lst[idx] is not None and reveal_type(lst[idx])
$ mypy foo.py
foo.py:6: note: Revealed type is 'builtins.int'
foo.py:7: note: Revealed type is 'Union[builtins.int, None]'

i would have expected mypy to also tell that the index lookup is identical when it's using a var idx and infer the type to be not-None

$ mypy --version
mypy 0.790+dev.fbc45aabdf46c820e81e3fc85e3d50b3ebf28ad0
@JukkaL
Copy link
Collaborator

JukkaL commented Aug 14, 2020

Closing as duplicate of #2199.

@JukkaL JukkaL closed this as completed Aug 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants