DeepSource has joined Harness. Learn more
Python logoPython/
PYL-E0601

Variable used before assignmentPYL-E0601

Critical severityCritical
Bug Risk categoryBug Risk

This local variable name is being used before it is defined. This will throw an UnboundLocalError. It is recommended to refactor this code.

Bad practice

def used_before_assignment(a):
    if x == a:  # x is defined in the next line
        for x in [1, 2]:
            pass
def correct_usage(a):
    for x in [1, 2]:
        if x == a:
            pass