pylint icon indicating copy to clipboard operation
pylint copied to clipboard

False positive of unused-import since v2.15.0

Open yilei opened this issue 1 year ago • 4 comments

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 avatar Sep 20 '22 18:09 yilei

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

mbyrnepr2 avatar Sep 20 '22 18:09 mbyrnepr2

We knew there was a risk of causing this false positive in https://github.com/PyCQA/astroid/pull/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).

jacobtylerwalls avatar Sep 21 '22 13:09 jacobtylerwalls

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

DanielNoord avatar Sep 21 '22 13:09 DanielNoord

I think it's a pylint problem.

jacobtylerwalls avatar Sep 21 '22 13:09 jacobtylerwalls

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

andybrewer avatar Oct 17 '22 15:10 andybrewer