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

Incorrect type inference in "if ham and spam is None: spam = ham; spam.startswith('/')" #4321

Closed
elprans opened this issue Dec 4, 2017 · 2 comments

Comments

@elprans
Copy link
Contributor

elprans commented Dec 4, 2017

Given the following code (test.py):

import typing
import urllib.parse


def _parse_dsn(*, dsn, database) -> dict:
    if dsn:
        parsed = urllib.parse.urlparse(dsn)
        if parsed.path and database is None:
            database = parsed.path
            if database.startswith('/'):  # this is line 10
                database = database[1:]

    return dict(database=database)

$ mypy test.py fails with:

test.py:10: error: "None" has no attribute "startswith"
test.py:11: error: Value of type "None" is not indexable

despite database provably not being None.

@elprans elprans changed the title Incorrect type inference in "if ham and spam is None: foo = ham; foo.startswith('/')" Incorrect type inference in "if ham and spam is None: spam = ham; spam.startswith('/')" Dec 4, 2017
@ilevkivskyi
Copy link
Member

I think this is essentially a duplicate of #3526 (although a bit special since in this case initial type is also Any).

@emmatyping
Copy link
Collaborator

Agreed. Closing as duplicate of #3526.

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

3 participants