Skip to content

Invalid type when variable name is the same as the type #4420

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
euresti opened this issue Jan 2, 2018 · 1 comment
Closed

Invalid type when variable name is the same as the type #4420

euresti opened this issue Jan 2, 2018 · 1 comment

Comments

@euresti
Copy link
Contributor

euresti commented Jan 2, 2018

This code:

from datetime import date
class A:
    date: date
reveal_type(A.date)

Leads to:

bar.py:5: error: Invalid type "bar.A.date"
bar.py:8: error: Revealed type is 'date?'

One workaround is:

import datetime
class A:
    date: datetime.date
reveal_type(A.date)

So it's not too bad.

@emmatyping
Copy link
Member

I believe this is a duplicate of #3775. Essentially, mypy's name resolution rules are slightly different from CPython's, so the class namespace is searched before the global namespace.

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