Skip to main content

Flake8 Builtins plugin

Check for python builtins being used as variables or parameters.

Imagine some code like this:

def max_values(list, list2):
    max = list[0]
    for x in list:
        if x > 0:
            max = x

    all_values = list()
    all_values.append(max)

    max = list2[0]
    for x in list2:
        if x > 0:
            max = x
    all_values.append(max)

    return all_values

max_values([3, 4, 5, ], [5, 6, 7])

The last statement is not returning [5, 7] as one would expect, instead is raising this exception::

Traceback (most recent call last):
  File "test.py", line 17, in <module>
    max_values([3,4,5], [4,5,6])
  File "bla.py", line 6, in max_values
    all_values = list()
TypeError: 'list' object is not callable

Why? Because max_value function's first argument is list a Python builtin. Python allows to override them, but although could be useful in some really specific use cases, the general approach is to not do that as code then can suddenly break without a clear trace.

Example

Given the following code:

def my_method(object, list, dict):
    max = 5
    min = 3
    zip = (4, 3)

The following warnings are shown (via flake8)::

test.py:1:15: A002 argument "object" is shadowing a python builtin
test.py:1:23: A002 argument "list" is shadowing a python builtin
test.py:1:29: A002 argument "dict" is shadowing a python builtin
test.py:2:5: A001 variable "max" is shadowing a python builtin
test.py:3:5: A001 variable "min" is shadowing a python builtin
test.py:4:5: A001 variable "zip" is shadowing a python builtin

Install

Install with pip::

python -m pip install flake8-builtins

Options

One can use --builtins-ignorelist option, or configuration option, to ignore a custom list of builtins::

flake8 --builtins-ignorelist id,copyright *.py

Requirements

  • Python 3.11, 3.12, 3.13, 3.14, 3.15 and pypy3
  • flake8

Rules

A001: A variable is shadowing a Python builtin.

A002: An argument is shadowing a Python builtin.

A003: A class attribute is shadowing a Python builtin.

A004: An import statement is shadowing a Python builtin.

A005: A module is shadowing a Python builtin module (e.g: logging or socket)

A006: A lambda argument is shadowing a Python builtin.

License

GPL 2.0

Metadata

Release files for flake8-builtins 3.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for flake8-builtins 3.2.0
File Size Uploaded Provenance Actions
flake8_builtins-3.2.0.tar.gz 18.4 kB Without provenance Details for flake8_builtins-3.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for flake8-builtins 3.2.0
File Interpreter ABI Platform Actions
flake8_builtins-3.2.0-py3-none-any.whl Python 3 none any Details for flake8_builtins-3.2.0-py3-none-any.whl

Total release size: 37.2 kB

Release files / flake8_builtins-3.2.0.tar.gz

Download URL flake8_builtins-3.2.0.tar.gz
Size 18.4 kB
Tags Source
SHA-256 checksum
How to use checksums
f0c4cee9028711349b7bf18e9a04282a613fd426e56af00bcd0c3bb61ae25481
BLAKE2b-256 checksum
How to use checksums
7cb92e42d77e5afe26439eba3df47c9764a4db2d88595531dea587afc3f9b823
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Release files / flake8_builtins-3.2.0-py3-none-any.whl

Download URL flake8_builtins-3.2.0-py3-none-any.whl
Size 18.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
192a00630f183b8e7b881e98def18aa20124581dde3a3e7be7a01a6effe3504b
BLAKE2b-256 checksum
How to use checksums
b602c7614f54d3fde51b8a20d91e14b012a01c78c2a481d36b5e8e40535a3d0b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Security for flake8-builtins 3.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

3.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page