Self Assignment
ID |
python.self_assignment |
Severity |
low |
Remediation Complexity |
trivial |
Remediation Risk |
low |
Remediation Effort |
low |
Resource |
Reliability |
Language |
Python |
Tags |
CWE:480, reliability, suspicious-construct |
Description
Reports plain assignments whose left-hand side and right-hand side have the same source text — x = x, self.value = self.value. The statement has no semantic effect and is almost always a typo of a surrounding refactor: the developer meant x = y or self.value = value.
x = x # FLAW
self.value = self.value # FLAW
x = x + 1 # OK — augmented form
self.value = value # OK — distinct names
Rationale
Self-assignment slips through review because each character of the line is correct in isolation. The bug is in the relationship between the two sides, which is exactly what a static rule can check cheaply.