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

Unreported undefined name in __all__ #280

Closed
adhikasp opened this issue Jun 19, 2017 · 4 comments
Closed

Unreported undefined name in __all__ #280

adhikasp opened this issue Jun 19, 2017 · 4 comments

Comments

@adhikasp
Copy link

adhikasp commented Jun 19, 2017

Pyflakes was unable to detect undefined name in __all__ when there exist undefined name outside of it. This make me need to use pyflakes 2 times to really detect all the errors.

For example, given this code...

from math import * # contain sin, cos, and csc
__all__ = ['sin', 'cos']
csc(1)

Pyflakes will report

test.py:1: 'from math import *' used; unable to detect undefined names
test.py:5: 'csc' may be undefined, or defined from star imports: math

According to that, the code just have 2 "error", which is usage of * import and csc is undefined.
If I then fix the code

from math import csc
__all__ = ['sin', 'cos']
csc(1)

Then additional error shown up

test.py:3: undefined name 'cos' in __all__
test.py:3: undefined name 'sin' in __all__

Which then could finally fixed by

from math import csc, cos, sin
__all__ = ['sin', 'cos']
csc(1)
@bitglue
Copy link
Member

bitglue commented Jun 20, 2017

What behavior do you expect? import * could import anything, so what could pyflakes do better than what it does now?

@asmeurer
Copy link
Contributor

He is saying there should be similar messages for sin and cos as the csc message.

@adhikasp
Copy link
Author

adhikasp commented Jun 26, 2017

@bitglue I was expecting that if pyflakes do want to report about that 2 kind of error, do it at the same time, not when the other issue was already gone (issue hidden at first sight)

@bitglue
Copy link
Member

bitglue commented Jun 26, 2017

It's "hidden" because pyflakes can't know what * imports. It's not until you explicitly declare what's in the namespace that pyflakes can tell you what's not in it.

CLiu13 added a commit to CLiu13/pyflakes that referenced this issue Nov 3, 2018
This allows pyflakes to report undefined names
in __all__ when import * is used, without having
to use pyflakes 2 times to detect the errors.

Fixes PyCQA#280
CLiu13 added a commit to CLiu13/pyflakes that referenced this issue Nov 3, 2018
This allows pyflakes to report undefined names
in __all__ when import * is used, without having
to use pyflakes 2 times to detect the errors.

Fixes PyCQA#280
CLiu13 added a commit to CLiu13/pyflakes that referenced this issue Nov 3, 2018
This allows pyflakes to report undefined names
in __all__ when import * is used, without having
to use pyflakes 2 times to detect the errors.

Fixes PyCQA#280
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