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}.")