redline
LowDesignglobal-statement

global

global. global x mutates module state from inside a function.

This is how the comment reads inline, under the flagged line.

Why it matters

Hidden global state makes functions order-dependent and tests interfere with each other.

What to do

Pass state in and return it, or keep it on an object.

Examples

Flagged
def bump():
    global count
    count += 1
Better
def bump(count):
    return count + 1

What it catches

It reads a pattern on each line, aware of strings and comments. Languages: Python. Scope: All files. These cases are the rule's own tests: the first set must be flagged and the second must not.

Flagged

def f():
    global x
    x = 1

Left alone

def f(x):
    return x

Research

`global` statements and module-level mutable state. Hidden coupling makes behavior depend on call order.

Turn it off or change it

In a config file for the CLI, or in the API's rules field:

{
  "rules": {
    "disable": [
      "global-statement"
    ],
    "severity": {
      "global-statement": "medium"
    }
  }
}

Read the source or report a false positive.