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

Mypy not detecting type narrowing in another function #8224

Closed
colinschoen opened this issue Dec 31, 2019 · 1 comment
Closed

Mypy not detecting type narrowing in another function #8224

colinschoen opened this issue Dec 31, 2019 · 1 comment

Comments

@colinschoen
Copy link

from typing import Optional, List
def is_not_none(lst):
    # type: (Optional[List[str]]) -> bool
    return lst is not None


def get_first_element(lst):
    # type: (Optional[List[str]]) -> str
    if is_not_none(lst):
        return lst[0]
    return 'not found'

mypy invocation: mypy --py2 .

Expected output:

Success: no issues found in 1 source file

Actual output

ex.py:12: error: Value of type "Optional[List[str]]" is not indexable
Found 1 error in 1 file (checked 1 source file)
@colinschoen colinschoen changed the title Mypy incorrectly detecting type narrowing in another function Mypy not detecting type narrowing in another function Dec 31, 2019
@ethanhs
Copy link
Collaborator

ethanhs commented Jan 1, 2020

This is a duplicate of #5206

@ethanhs ethanhs closed this as completed Jan 1, 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