An assignment stores a name's value back into the same name
What it finds
x = x in a function: assigning a local variable to itself does nothing, and usually stands for an assignment to something else, such as an attribute of the same name.
Only names in functions are checked. In a class body name = name copies a global into the class, and at the top of a module it marks an import as used. self.x = self.x can run a property setter or turn a class attribute into an instance attribute, and a[i] = a[i] calls __setitem__. An assignment that makes up a whole branch of an if statement, as in else: x = x, says on purpose that the value stays.
From the rule's source, self_assignment.rs.
name = name class Config: debug = debug def set(self, value, other): value = valuetx0 reports: value is assigned to itself value, other = value, 2tx0 reports: value is assigned to itself value, other = other, value self.value = self.value self.items[0] = self.items[0] first, *rest = (value, *other) if value: value = value.strip() else: value = value handler = lambda: value return handler 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:self-assignment" = "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:self-assignment] reason="..."tx0 explain tx0/python:self-assignment shows the same in the terminal. Found a false positive? Report it.