PY3.E0118

Used prior global declaration

Emitted when a name is used prior a global declaration, which results in an error since Python 3.6.

Noncompliant Code:

Copy
MSG = 'Outside'
def foo():
    print(MSG)

    global MSG
    MSG = 'Inside'
    print(MSG)

Compliant Code:

Copy
MSG = 'Outside'
def foo():
    global MSG
    print(MSG)

    MSG = 'Inside'
    print(MSG)

The content on this page is adapted from the Pylint User Guide, Copyright ©2003-2022, Logilab, PyCQA and contributors. All rights reserved. https://pylint.pycqa.org/en/latest/index.html#, and is used under the Python Software Foundation License Version 2. Examples, recipes, and other code in the Pylint documentation are additionally licensed under the Zero Clause BSD License.