undefined-loop-variable / W0631#

Message emitted:

Using possibly undefined loop variable %r

Description:

Used when a loop variable (i.e. defined by a for loop or a list comprehension or a generator expression) is used outside the loop.

Correct code:

def find_even_number(numbers):
    for x in numbers:
        if x % 2:
            return x
    return None

Problematic code:

def find_even_number(numbers):
    for x in numbers:
        if x % 2 == 0:
            break
    return x  # [undefined-loop-variable]

Created by the variables checker.