Skip to content

Warn on unnecessary use of global #492

Description

@Zac-HD
CONSTANT = 1

def fn(x):
    global CONSTANT  # <- unnecessary, unidiomatic, and a (small) performance hit
    return x + CONSTANT

The global statement is only required when assigning to a global variable; you can reference outer namespaces without it. I think it'd be nice to have a lint rule that pointed this out, to help newer Pythonistas understand how scoping works.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions