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

unused-import should observe dummy-variables-rgx setting #8500

Closed
macdjord opened this issue Mar 28, 2023 · 3 comments · Fixed by #8566 or #9093
Closed

unused-import should observe dummy-variables-rgx setting #8500

macdjord opened this issue Mar 28, 2023 · 3 comments · Fixed by #8566 or #9093
Assignees
Labels
Enhancement ✨ Improvement to a component Good first issue Friendly and approachable by new contributors Help wanted 🙏 Outside help would be appreciated, good for new contributors Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Milestone

Comments

@macdjord
Copy link

Bug description

Python convention is that any variable name consisting entirely of underscores is to be considered a placeholder, used when a value needs to be assigned somewhere but you don't actually care about it after that. Thus no warnings should be emitted about such a variable being unused, overwritten, or changing type.

However, another common convention is to import the gettext() translation function as _ for convenience. Thus current best-practice is to use names of two or more underscores for placeholders.

test2.py:

"""Test"""

import prettyprinter as __

Configuration

No response

Command used

pylint test2.py

Pylint output

************* Module test2
test2.py:3:0: W0611: Unused prettyprinter imported as __ (unused-import)

------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)

Expected behavior

No unused-import should be emitted if the module is imported with a name consisting entirely of underscores.

Pylint version

pylint 2.16.2
astroid 2.14.2
Python 3.11.2 (tags/v3.11.2:878ead1, Feb  7 2023, 16:38:35) [MSC v.1934 64 bit (AMD64)]

OS / Environment

Win10

Additional dependencies

No response

@macdjord macdjord added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Mar 28, 2023
@DanielNoord
Copy link
Collaborator

I have never seen this pattern. How common is this?

@jacobtylerwalls
Copy link
Member

jacobtylerwalls commented Mar 28, 2023

I have seen the get_text alias as _.

I think we should accept this on the basis that unused-import should observe the dummy-variables-rgx config argument. Right now the check only checks for a hardcoded _. Then this message will have parity with unused-variable. The default for that variable already checks underscores at the start of a string.

Easy picking. Thanks for the report!

@jacobtylerwalls jacobtylerwalls added Enhancement ✨ Improvement to a component Help wanted 🙏 Outside help would be appreciated, good for new contributors Good first issue Friendly and approachable by new contributors and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Mar 28, 2023
@jacobtylerwalls jacobtylerwalls changed the title False positive unused-import when imported as __ unused-import should observe dummy-variables-rgx setting Mar 28, 2023
@jacobtylerwalls jacobtylerwalls added the Needs PR This issue is accepted, sufficiently specified and now needs an implementation label Mar 28, 2023
@RSTdefg
Copy link
Contributor

RSTdefg commented Mar 29, 2023

Hello, I've looked into this issue and I'd like to work on it. Thanks!

RSTdefg added a commit to RSTdefg/pylint that referenced this issue Apr 11, 2023
`unused-import` now observes `dummy-variables-rgx config`
Resolves pylint-dev#8500
RSTdefg added a commit to RSTdefg/pylint that referenced this issue Apr 11, 2023
`unused-import` now observes `dummy-variables-rgx config`
Resolves pylint-dev#8500
RSTdefg added a commit to RSTdefg/pylint that referenced this issue Apr 12, 2023
@Pierre-Sassoulas Pierre-Sassoulas added this to the 2.17.3 milestone Apr 12, 2023
Pierre-Sassoulas added a commit that referenced this issue Apr 12, 2023
Resolve #8500

Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
github-actions bot pushed a commit that referenced this issue Apr 12, 2023
Resolve #8500

Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
(cherry picked from commit 0cd41b1)
Pierre-Sassoulas pushed a commit that referenced this issue Apr 12, 2023
Resolve #8500

Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
(cherry picked from commit 0cd41b1)

Co-authored-by: RSTdefg <34202999+RSTdefg@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ✨ Improvement to a component Good first issue Friendly and approachable by new contributors Help wanted 🙏 Outside help would be appreciated, good for new contributors Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
5 participants