Shadowing Built-in Names

ID

python.shadowing_builtins

Severity

low

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Reliability

Language

Python

Tags

naming, reliability

Description

Reports names that shadow a Python builtin — function definitions (def list(): …​), local assignments (dict = {}), and formal parameters (def f(type): …​). Once a builtin is shadowed in a scope, every reference to that name resolves to the local instead of the builtin, which leads to surprising failures far from the assignment (dict({"a": 1}) suddenly raises TypeError: 'dict' object is not callable).

list = [1, 2, 3]               # FLAW

def type(x):                   # FLAW
    return x.__class__

def parse(input):              # FLAW
    return input.strip()

values = [1, 2, 3]             # OK
def parse_input(text):         # OK
    return text.strip()

Rationale

The list of shadowed names is configurable, but the defaults focus on identifiers most often shadowed unintentionally — typically because they read as plain English nouns (list, type, format, id).

Remediation

Pick a more specific name. Common conventions: prefix with the kind (raw_list, result_dict), suffix with value / _obj, or trail with an underscore (type, id_) when nothing better fits.

Configuration

The set of names checked can be overridden via the rule’s names property in the scan profile.