CodeQL documentation

Variable defined multiple times

ID: py/multiple-definition
Kind: problem
Security severity: 
Severity: warning
Precision: very-high
   - maintainability
   - useless-code
   - external/cwe/cwe-563
Query suites:
   - python-security-and-quality.qls

Click to see the query in the CodeQL repository

Multiple assignments to a single variable without an intervening usage makes the first assignment redundant. Its value is lost.


Ensure that the second assignment is in fact correct. Then delete the first assignment (taking care not to delete right hand side if it has side effects).


In this example, x is assigned the value of 42 but then the value is changed to 12 before x is used. This makes the first assignment useless.

x = 42
x = 12
print x


  • © GitHub, Inc.
  • Terms
  • Privacy