pylint-errors

E0117 (nonlocal-without-binding)

:x: Problematic code:

def foo():
    def bar():
        nonlocal msg
        msg = 'Inside'

    bar()
    print(msg)

:heavy_check_mark: Correct code:

def foo():
    msg = 'Outside'

    def bar():
        nonlocal msg
        msg = 'Inside'

    bar()
    print(msg)

Rationale:

Emitted when a nonlocal variable does not have an attached name somewhere in the parent scopes.