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

False positive finding for E0605: Invalid format for __all__ #4711

Closed
kasium opened this issue Jul 15, 2021 · 10 comments · Fixed by #4829 or #4953
Closed

False positive finding for E0605: Invalid format for __all__ #4711

kasium opened this issue Jul 15, 2021 · 10 comments · Fixed by #4829 or #4953
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code
Milestone

Comments

@kasium
Copy link
Contributor

kasium commented Jul 15, 2021

Steps to reproduce

Given a file __init__.py:

from foo import bar
__all__ = list(globals().keys())

Current behavior

Result of pylint __init__.py:

configuration:1:0: E0605: Invalid format for __all__, must be tuple or list (invalid-all-format)

Expected behavior

No finding. The attribute is a list at runtime but I guess the check doesn't see this

pylint --version output

Result of pylint --version output:

pylint 2.9.3
astroid 2.6.2
Python 3.7.1 (default, Oct 22 2018, 13:16:18) [GCC]
@Pierre-Sassoulas Pierre-Sassoulas added the False Positive 🦟 A message is emitted but nothing is wrong with the code label Jul 15, 2021
tyralla added a commit to hydpy-dev/hydpy that referenced this issue Aug 6, 2021
@kasium
Copy link
Contributor Author

kasium commented Aug 11, 2021

So I did some troubleshooting. The type of the list at pylint time is <Instance of builtins.list at 0x140612117943968>

So, the check fails here: https://github.com/PyCQA/pylint/blob/741276e90a3698c8bf5ac621669453b67b7c2c7c/pylint/checkers/variables.py#L2013

@Pierre-Sassoulas
Copy link
Member

If I understand what you're saying the fix could be : if not isinstance(assigned, (astroid.Tuple, astroid.List, list)): ? Could you try to open a merge request and add a functional test in tests/functional/ to get the authorship of your fix ? :)

@kasium
Copy link
Contributor Author

kasium commented Aug 11, 2021

I guess that could be the fix 😄 . Let me give it a try

@kasium
Copy link
Contributor Author

kasium commented Sep 1, 2021

@Pierre-Sassoulas bad new, still not fixed.

I'm not sure, but it seems, that these "_valid_x.py" files are not running in the tests at all. Can you please check.

Also , the module name of the finding is false:

************* Module builtins
configuration:1:0: E0605: Invalid format for __all__, must be tuple or list (invalid-all-format)

The module builtins and filename configuration make no sense. I guess that this code
https://github.com/PyCQA/pylint/blob/741276e90a3698c8bf5ac621669453b67b7c2c7c/pylint/checkers/variables.py#L2014
should have node=node.

@Pierre-Sassoulas
Copy link
Member

Thank you for finding that bug with the bad node being given. The valid_x file are all being executed but the example given in this issue is not tested in it. It's still giving:

************* Module invalid_all_format_valid_5
tests/functional/i/invalid/invalid_all_format_valid_5.py:1:0: E0605: Invalid format for __all__, must be tuple or list (invalid-all-format)

See #4953

@kasium
Copy link
Contributor Author

kasium commented Sep 1, 2021

Thanks a lot for the quick help and the PR. It would be great to see this in a 2.10.x release 😄

A quick question: The line number seems to be wring, too. Shouldn't it be 7?

@Pierre-Sassoulas
Copy link
Member

The PR is fixing the bad node but not yet the false positive. It's a basis for working on it :)

@kasium
Copy link
Contributor Author

kasium commented Sep 10, 2021

So, the actual type is an astroid instance object which represents builtins.list. Not sure how to check for that.
One option would be to use assigned.pytype() == 'builtins.list'. What do you think?

Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Sep 13, 2021
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Sep 13, 2021
Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Sep 13, 2021
@Pierre-Sassoulas
Copy link
Member

You're right, I also handled tuple the same way.

@kasium
Copy link
Contributor Author

kasium commented Sep 13, 2021

Great 😄

Pierre-Sassoulas added a commit to Pierre-Sassoulas/pylint that referenced this issue Sep 13, 2021
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.11.0 milestone Sep 13, 2021
Pierre-Sassoulas added a commit that referenced this issue Sep 13, 2021
…r ``__all__`` (#4953)

* Fix bad node being given as context for message

See #4711

* Add a functional test for issue #4711

* Fix false positive invalid-all-format

Closes #4711
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code
Projects
None yet
2 participants