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

deterministic ordering for errors in __all__ #604

Merged
merged 1 commit into from
Jan 4, 2021
Merged

deterministic ordering for errors in __all__ #604

merged 1 commit into from
Jan 4, 2021

Conversation

asottile
Copy link
Member

@asottile asottile commented Jan 4, 2021

Resolves #603

I couldn't figure out a way to test this that wasn't flakey and without writing a bunch of test infra to look at the actual messages (since they're all the same type)

Here's a demo of the fix however:

$ python3 -m pyflakes t.py
t.py:1:1 undefined name 'a' in __all__
t.py:1:1 undefined name 'b' in __all__
t.py:1:1 undefined name 'c' in __all__
t.py:1:1 undefined name 'd' in __all__
$ python3 -m pyflakes t.py
t.py:1:1 undefined name 'a' in __all__
t.py:1:1 undefined name 'b' in __all__
t.py:1:1 undefined name 'c' in __all__
t.py:1:1 undefined name 'd' in __all__
$ python3 -m pyflakes t.py
t.py:1:1 undefined name 'a' in __all__
t.py:1:1 undefined name 'b' in __all__
t.py:1:1 undefined name 'c' in __all__
t.py:1:1 undefined name 'd' in __all__
$ python3 -m pyflakes t.py
t.py:1:1 undefined name 'a' in __all__
t.py:1:1 undefined name 'b' in __all__
t.py:1:1 undefined name 'c' in __all__
t.py:1:1 undefined name 'd' in __all__
$ python3 -m pyflakes t.py
t.py:1:1 undefined name 'a' in __all__
t.py:1:1 undefined name 'b' in __all__
t.py:1:1 undefined name 'c' in __all__
t.py:1:1 undefined name 'd' in __all__

@@ -992,7 +992,10 @@ def checkDeadScopes(self):

if all_binding:
all_names = set(all_binding.names)
undefined = all_names.difference(scope)
undefined = [
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we can drop all_names or if the usage on L1026 is really that much faster just because it's a set in practice on real code-bases

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I thought about this, but I don't really have a good way to profile this. I imagine it's not a significant difference to keep the original value as a list and just do in against that (however it does appear to change this from O(N) + O(M) to O(N * M) where N is the number of imports and M is the number of items in __all__

Probably ok to just leave it since it keeps this change a little bit more minimal

Copy link
Member

@sigmavirus24 sigmavirus24 left a comment

Choose a reason for hiding this comment

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

Non-blocking thought in-line

@asottile
Copy link
Member Author

asottile commented Jan 4, 2021

@sigmavirus24 while I have you, can you click disable in appveyor so we don't get the empty failure?

@asottile asottile merged commit 650efb9 into PyCQA:master Jan 4, 2021
@asottile asottile deleted the deterministic_all branch January 4, 2021 22:08
This was referenced Mar 15, 2021
This was referenced Mar 15, 2021
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.

"undefined name in __all__" has non-deterministic ordering
2 participants