Skip to content

Allow __getattr__ during semantic analysis #5295

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

Merged
merged 4 commits into from
Jun 29, 2018

Conversation

ilevkivskyi
Copy link
Member

Previously module __getattr__ was used during type checking (runtime context). But it was only partially allowed in semantic analysis (after from a import A, A can be used in annotations/base classes). This PR allows the same support for a.A, i.e. it can be used in annotations and base classes (provided __getattr__ has a suitable return type Any).

@ilevkivskyi ilevkivskyi requested a review from msullivan June 28, 2018 22:25
Copy link
Collaborator

@msullivan msullivan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

Are these bugs run into working on sqlalchemy typing?

mypy/semanal.py Outdated
v = Var(name, type=typ)
v._fullname = name
n = SymbolTableNode(GDEF, v)
names[name] = n
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be worth pulling this out into another method, since it is a big chunk of code for an obscure case.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I there is also similar code above in visit_import_from, it would make sense to combine the two into a helper method. I will do this tomorrow.

@ilevkivskyi
Copy link
Member Author

Are these bugs run into working on sqlalchemy typing?

Yes. I am slowly moving through existing stubs and trying to combine them with some __getattr__s to make a "partial" package.

@ilevkivskyi
Copy link
Member Author

testpr is also clean so I am merging now.

@ilevkivskyi ilevkivskyi merged commit d91efd4 into python:master Jun 29, 2018
@ilevkivskyi ilevkivskyi deleted the getattr-semanal branch June 29, 2018 17:04
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

Successfully merging this pull request may close these issues.

2 participants