nonlocal-and-global / E0115#

Message emitted:

Name %r is nonlocal and global

Description:

Emitted when a name is both nonlocal and global.

Correct code:

NUMBER = 42


def update_number(number):
    global NUMBER
    NUMBER = number
    print(f"New global number is: {NUMBER}")


update_number(24)

Problematic code:

NUMBER = 42


def update_number(number):  # [nonlocal-and-global]
    global NUMBER
    nonlocal NUMBER
    NUMBER = number
    print(f"New global number is: {NUMBER}")


update_number(24)

Created by the basic checker.