pylint-dev / pylint

It's not just a linter that annoys you!
https://pylint.readthedocs.io/en/latest/
GNU General Public License v2.0
5.33k stars 1.14k forks source link

E1136/E1137 false positives #10082

Open bje- opened 1 week ago

bje- commented 1 week ago

Bug description

False positive E1136 and E1137 warnings from the following code:

"""docstring"""
import pandas as pd

class TraceLoad:
    """docstring"""
    csvdata = None

    def __init__(self, filename):
        """docstring"""
        cls = self.__class__
        cls.csvdata = pd.read_csv(filename, comment='#', sep=',')
        cls.csvdata['Date_Time'] = \
            pd.to_datetime(cls.csvdata['Date'] + ' ' + cls.csvdata['Time'])

Configuration

Command used

pylint example.py

Pylint output

************* Module example
example.py:12:8: E1137: 'cls.csvdata' does not support item assignment (unsupported-assignment-operation)
example.py:13:27: E1136: Value 'cls.csvdata' is unsubscriptable (unsubscriptable-object)
example.py:13:55: E1136: Value 'cls.csvdata' is unsubscriptable (unsubscriptable-object)

Expected behavior

No warnings.

Pylint version

pylint 3.3.1
astroid 3.3.5
Python 3.12.3 (main, Sep 11 2024, 14:17:37) [GCC 13.2.0]

OS / Environment

Ubuntu 24.04

Additional dependencies

pandas==2.2.3
bje- commented 1 week ago

I discovered that this only happens if csvdata is a class member. If I change the test case to just assign a local variable inside the __init__ function, the warnings go away.