Skip to content

Error when type annotation shadows import "Invalid type ..." #6188

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
asottile opened this issue Jan 13, 2019 · 1 comment
Closed

Error when type annotation shadows import "Invalid type ..." #6188

asottile opened this issue Jan 13, 2019 · 1 comment

Comments

@asottile
Copy link
Contributor

import datetime
from typing import NamedTuple


class C(NamedTuple):
    datetime: datetime.datetime


print(C.__annotations__)
$ python t.py
OrderedDict([('datetime', <class 'datetime.datetime'>)])
$ mypy --version
mypy 0.650
$ mypy t.py
t.py:6: error: Invalid type "t.C.datetime"

I ended up renaming my attribute, though as far as I can tell this is legal code that mypy is rejecting

@ilevkivskyi
Copy link
Member

This is essentially a duplicate of #3775, in particular see this comment #3775 (comment)

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