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

Don't consider __future__ imports and __all__ unused #10019

Open
Syndace opened this issue Oct 14, 2024 · 5 comments
Open

Don't consider __future__ imports and __all__ unused #10019

Syndace opened this issue Oct 14, 2024 · 5 comments
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code

Comments

@Syndace
Copy link

Syndace commented Oct 14, 2024

Bug description

from __future__ import annotations

__all__ = [ "foo" ]

def foo():
    pass

Command used

pylint foo.py --allow-global-unused-variables n

Pylint output

************* Module foo
...
foo.py:3:0: W0612: Unused variable '__all__' (unused-variable)
foo.py:1:0: W0612: Unused variable 'annotations' (unused-variable)

Expected behavior

Imports from __future__ and the __all__ variable are implicitly used by the interpreter and should as such not be considered unused, even with --allow-global-unused-variables n.

Pylint version

All versions

@Syndace Syndace added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Oct 14, 2024
@Pierre-Sassoulas
Copy link
Member

I can't reproduce with the latest version. Could you install pylint 3.3.1 and confirm the issue please ?

@Pierre-Sassoulas Pierre-Sassoulas added Cannot reproduce 🤷 Waiting on author Indicate that maintainers are waiting for a message of the author and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Oct 14, 2024
@Syndace
Copy link
Author

Syndace commented Oct 14, 2024

Yes, I'm on the latest version:

pylint 3.3.1
astroid 3.3.5
Python 3.12.7 (main, Oct  1 2024, 11:15:50) [GCC 14.2.1 20240910]

@Syndace
Copy link
Author

Syndace commented Oct 14, 2024

Specifically, I'm on Arch and used the following commands:

$ python3 -m venv env
$ source env/bin/activate
$ pip install --upgrade pylint
$ pylint foo.py --allow-global-unused-variables n

@Pierre-Sassoulas Pierre-Sassoulas added Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling False Positive 🦟 A message is emitted but nothing is wrong with the code and removed Cannot reproduce 🤷 Waiting on author Indicate that maintainers are waiting for a message of the author Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Oct 14, 2024
@Pierre-Sassoulas
Copy link
Member

Thank you, it only happens with --allow-global-unused-variables n

@Syndace
Copy link
Author

Syndace commented Oct 15, 2024

I encountered another false positive I believe. Re-exports from __init__.py with --allow-reexport-from-package y should not be considered unused globals. Here is an updated example that reproduces all three cases:

__init__.py:

from .test import test as test

test.py:

from __future__ import annotations

__all__ = [ "test" ]

def test():
    pass

Command:

pylint --allow-global-unused-variables n --allow-reexport-from-package y .

Output (docstring warnings omitted):

************* Module global_unused
__init__.py:1:0: W0612: Unused variable 'test' (unused-variable)
************* Module global_unused.test
test.py:3:0: W0612: Unused variable '__all__' (unused-variable)
test.py:1:0: W0612: Unused variable 'annotations' (unused-variable)

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
Development

No branches or pull requests

2 participants