A name in __slots__ is also a class attribute, and defining the class raises ValueError
What it finds
__slots__ = ("name",) together with name = "unknown" in the class body: a slot is a descriptor stored under the same class attribute, so defining both raises ValueError: 'name' in __slots__ conflicts with class variable when the class is created. A default for a slot belongs in __init__.
__slots__ must be a list or tuple display of string literals. Methods with the name of a slot conflict too. Classes given a metaclass or other keywords, which may take the attributes out first, and stubs are left alone.
From the rule's source, slots_conflict.rs.
class Point: __slots__ = ("x", "y") x = 0tx0 reports: x is in __slots__ and also a class attribute, so defining the class raises ValueError def y(self):tx0 reports: y is in __slots__ and also a class attribute return 1 class Fine: __slots__ = ["name"] other = 1 Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/python:slots-conflict" = "off"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
# tx0: ignore[tx0/python:slots-conflict] reason="..."tx0 explain tx0/python:slots-conflict shows the same in the terminal. Found a false positive? Report it.