PY3.E0242

Cass variable slots conflict

Used when a value in slots conflicts with a class variable, property or method.

Noncompliant Code:

Copy
class Person:
    __slots__ = ("age", "name", "say_hi",)
    name = None

    def __init__(self, age, name):
        self.age = age
        self.name = name

    @property
    def age(self):
        return self.age

    def say_hi(self):
        print(f"Hi, I'm {self.name}.")

Compliant Code:

Copy
class Person:
    __slots__ = ("_age", "name",)

    def __init__(self, age, name):
        self._age = age
        self.name = name

    @property
    def age(self):
        return self._age

    def say_hi(self):
        print(f"Hi, I'm {self.name}.")

The content on this page is adapted from the Pylint User Guide, Copyright ©2003-2022, Logilab, PyCQA and contributors. All rights reserved. https://pylint.pycqa.org/en/latest/index.html#, and is used under the Python Software Foundation License Version 2. Examples, recipes, and other code in the Pylint documentation are additionally licensed under the Zero Clause BSD License.