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 of unused-import since v2.15.0 #7506

Closed
yilei opened this issue Sep 20, 2022 · 7 comments · Fixed by #8432 or #9093
Closed

False positive of unused-import since v2.15.0 #7506

yilei opened this issue Sep 20, 2022 · 7 comments · Fixed by #8432 or #9093
Assignees
Labels
False Positive 🦟 A message is emitted but nothing is wrong with the code Needs astroid update Needs an astroid update (probably a release too) before being mergable Regression
Milestone

Comments

@yilei
Copy link
Contributor

yilei commented Sep 20, 2022

Bug description

Given the following code:

# pylint: disable=missing-docstring,too-few-public-methods

import abc
import six


class MyClass(six.with_metaclass(abc.ABCMeta)):
    pass

Configuration

No response

Command used

pylint a.py

Pylint output

************* Module t
t.py:4:0: W0611: Unused import six (unused-import)

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

Expected behavior

No unused-import should be raised

Pylint version

pylint 2.15.0
astroid 2.12.10
Python 3.9.13 (main, Jun  1 2022, 14:19:10)
[GCC 11.2.0]

This cannot be reproduced in v2.14.5.



### OS / Environment

_No response_

### Additional dependencies

_No response_
@yilei yilei added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Sep 20, 2022
@mbyrnepr2 mbyrnepr2 added Regression False Positive 🦟 A message is emitted but nothing is wrong with the code Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Sep 20, 2022
@mbyrnepr2
Copy link
Member

Thank you @yilei. I can reproduce on the latest version of Pylint/astroid & also see no false positive on Pylint==2.14.5:

pylint 2.16.0-dev
astroid 2.12.10
Python 3.10.4

@jacobtylerwalls
Copy link
Member

We knew there was a risk of causing this false positive in pylint-dev/astroid#1622, but I thought we checked that we handled it (I suppose not). Closely related to #1630 (might need to broaden that issue title back out).

@DanielNoord
Copy link
Collaborator

Should this be fixed in astroid or should pylint also check the bases of a ClassDef for "used-imports"?

@jacobtylerwalls
Copy link
Member

I think it's a pylint problem.

@andybrewer
Copy link

Maybe a similar issue with pandas_ta:

import pandas as pd
# https://github.com/twopirllc/pandas-ta
import pandas_ta as ta

df = pd.read_csv('data.csv')
df.ta.ad()

produces:
Unused pandas_ta imported as ta

@tushar-deepsource
Copy link
Contributor

This should be relevant: pylint-dev/astroid#1735

@jacobtylerwalls jacobtylerwalls added Needs astroid update Needs an astroid update (probably a release too) before being mergable and removed Needs PR This issue is accepted, sufficiently specified and now needs an implementation labels Mar 11, 2023
@jacobtylerwalls jacobtylerwalls self-assigned this Mar 11, 2023
@jacobtylerwalls jacobtylerwalls added this to the 2.17.1 milestone Mar 11, 2023
jacobtylerwalls added a commit to jacobtylerwalls/astroid that referenced this issue Mar 11, 2023
Harden support for using enums as metaclasses.

Fixes the crash in pylint-dev/pylint#5935 by adopting the check
for not-none bases as in ClassDef._inferred_bases without recausing
the false positive reported in pylint-dev/pylint#7506, which requires
correct bases.
@jacobtylerwalls
Copy link
Member

I think it's a pylint problem.

Turns out it was an astroid problem. Regression test PR coming shortly, will fail until upgrading astroid.

jacobtylerwalls added a commit to jacobtylerwalls/pylint that referenced this issue Mar 11, 2023
jacobtylerwalls added a commit to jacobtylerwalls/astroid that referenced this issue Mar 12, 2023
Harden support for using enums as metaclasses.

Fixes the crash in pylint-dev/pylint#5935 by adopting the check
for not-none bases as in ClassDef._inferred_bases without recausing
the false positive reported in pylint-dev/pylint#7506, which requires
correct bases.
@Pierre-Sassoulas Pierre-Sassoulas modified the milestones: 2.17.1, 2.17.2 Mar 22, 2023
jacobtylerwalls added a commit to pylint-dev/astroid that referenced this issue Mar 26, 2023
…s` (#2049)

Harden support for using enums as metaclasses.

Fixes the crash in pylint-dev/pylint#5935 by adopting the check
for not-none bases as in ClassDef._inferred_bases without recausing
the false positive reported in pylint-dev/pylint#7506, which requires
correct bases.
github-actions bot pushed a commit to pylint-dev/astroid that referenced this issue Mar 26, 2023
…s` (#2049)

Harden support for using enums as metaclasses.

Fixes the crash in pylint-dev/pylint#5935 by adopting the check
for not-none bases as in ClassDef._inferred_bases without recausing
the false positive reported in pylint-dev/pylint#7506, which requires
correct bases.

(cherry picked from commit b5ebf99)
Pierre-Sassoulas pushed a commit to pylint-dev/astroid that referenced this issue Mar 26, 2023
…s` (#2049) (#2067)

Harden support for using enums as metaclasses.

Fixes the crash in pylint-dev/pylint#5935 by adopting the check
for not-none bases as in ClassDef._inferred_bases without recausing
the false positive reported in pylint-dev/pylint#7506, which requires
correct bases.

(cherry picked from commit b5ebf99)

Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
jacobtylerwalls added a commit to jacobtylerwalls/pylint that referenced this issue Apr 1, 2023
github-actions bot pushed a commit that referenced this issue Apr 3, 2023
(cherry picked from commit 1fa16c2)
Pierre-Sassoulas pushed a commit that referenced this issue Apr 3, 2023
(cherry picked from commit 1fa16c2)
Pierre-Sassoulas added a commit that referenced this issue Apr 3, 2023
* Add regression test for #7506 (#8432)

(cherry picked from commit 1fa16c2)

---------

Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
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 Needs astroid update Needs an astroid update (probably a release too) before being mergable Regression
Projects
None yet
7 participants