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

Pyre can't find names using __getattr__ #286

Closed
dirn opened this issue Aug 3, 2020 · 2 comments
Closed

Pyre can't find names using __getattr__ #286

dirn opened this issue Aug 3, 2020 · 2 comments

Comments

@dirn
Copy link
Contributor

dirn commented Aug 3, 2020

When trying to import from a module that uses __getattr__ in its stub file, pyre can't find the name. For example

from django.contrib.auth.decorators import login_required

results in

Undefined import [21]: Could not find a name `login_required` defined in module `django.contrib.auth.decorators`.

This import worked prior to 5f1d94d. I'm running into this in PyGotham/awards#78, but I'm able to reproduce this in a file that just contains the import.

@arthaud
Copy link
Contributor

arthaud commented Aug 3, 2020

Hi @dirn, thanks for the report!

This is another bug in our stubs: we replaced placeholder stubs # pyre-placeholder-stub with __getattr__() -> Any where it should be __getattr__(name: str) -> Any. I will fix that soon.

dirn added a commit to dirn/pyre-check that referenced this issue Aug 4, 2020
When Python calls a module's `__getattr__` function, it passes it the
name of the attribute. Without including the argument in the signature,
Pyre can't find module attributes not explicitly included in the stubs.
This results in `Undefinied import` errors.

To address this, a `name` argument (typed as `str`) is being added to
each `__getattr__` stub.

Fixes facebook#286
@arthaud
Copy link
Contributor

arthaud commented Aug 4, 2020

This should be fixed in 0dd5c8f. Thanks for the report :)

@arthaud arthaud closed this as completed Aug 4, 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

Successfully merging a pull request may close this issue.

2 participants