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-variable false positive #4020

Closed
douglas-raillard-arm opened this issue Jan 8, 2021 · 2 comments · Fixed by #6481
Closed

unused-variable false positive #4020

douglas-raillard-arm opened this issue Jan 8, 2021 · 2 comments · Fixed by #6481
Labels
Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code
Milestone

Comments

@douglas-raillard-arm
Copy link

Steps to reproduce

This seems to be the minimal reproducer,

def f():
    def g():
        return type

    class C(metaclass=g()):
        pass

    return C

Current behavior

test.py:5:4: W0612: Unused variable 'g' (unused-variable)

Expected behavior

No error, since the function is used.

pylint --version output

pylint 2.6.0
astroid 2.4.2
Python 3.8.7 (default, Dec 24 2020, 17:53:09) 
[GCC 10.2.0]
@hippo91
Copy link
Contributor

hippo91 commented Jan 16, 2021

@douglas-raillard-arm thanks for the report. I can reproduce it.

@hippo91 hippo91 added Bug 🪲 False Positive 🦟 A message is emitted but nothing is wrong with the code labels Jan 16, 2021
@sudomyju
Copy link

sudomyju commented Jan 26, 2021

Hi guys,

same applies for cycle/s (I guess)

def ster(oids):
    for i in range(oids)
        print("oids")

while in the cycle (it is kind of disputable) if it is really unused when it runs the cycle, I think the better pylint result in this case would be either some "info" like "Consider using _ when not planning to utilize the variable used for constructing the cycle".

(On other hand, I don't understand why are the real problems/errors are mixed up with some sort of highly opinioned assumptions on how the code should look like of pylint's which are considered errors as well.
where the prime example of this is sort of error is being considering an empty line a triling space!)

astroid 2.4.2
Python 3.7.0 (v3.7.0:1bf9cc5093, Jun 27 2018, 04:06:47) [MSC v.1914 32 bit (Intel)]

Hope this helps,
Su

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

Successfully merging a pull request may close this issue.

4 participants