Skip to content

Assignments to class attributes inside __init__() are not inferred #9250

@bje-

Description

@bje-

Bug description

Pylint produces an incorrect unsubscriptable-object warning.

"""A test case."""
import numpy as np

class Foo:
    """Class docstring."""

    csvfilename = None
    csvdata = None

    def __init__(self, filename):
        cls = self.__class__
        assert filename is not None
        if cls.csvfilename != filename:
            cls.csvdata = np.zeros(10)
            cls.csvfilenanme = filename
        self.generation = cls.csvdata[0]

Command used

pylint testcase.py

Pylint output

************* Module testcase
testcase.py:16:26: E1136: Value 'cls.csvdata' is unsubscriptable (unsubscriptable-object)

Expected behavior

No warning should be emitted.

Pylint version

pylint 3.0.2
astroid 3.0.1
Python 3.10.12 (main, Jun 11 2023, 05:26:28) [GCC 11.4.0]

OS / Environment

Ubuntu 22.04

Metadata

Metadata

Assignees

No one assigned

    Labels

    AstroidRelated to astroidEnhancement ✨Improvement to a componentNeeds PRThis issue is accepted, sufficiently specified and now needs an implementation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions