Redundant assignmentΒΆ
ID: py/redundant-assignment
Kind: problem
Severity: error
Precision: very-high
Tags:
- reliability
- useless-code
- external/cwe/cwe-563
Query suites:
- python-security-and-quality.qls
Click to see the query in the CodeQL repository
Assigning a variable to itself is redundant and often an indication of a mistake in the code.
RecommendationΒΆ
Check the assignment carefully for mistakes. If the assignment is truly redundant and not simply incorrect then remove it.
ExampleΒΆ
In this example the programmer clearly intends to assign to self.eggs but made a mistake.
class Spam:
def __init__(self, eggs):
eggs = eggs
ReferencesΒΆ
Python Language Reference: The assignment statement.
Common Weakness Enumeration: CWE-563.