Skip to main content
https://travis-ci.org/gforcada/flake8-builtins.svg?branch=master https://coveralls.io/repos/gforcada/flake8-builtins/badge.svg?branch=master&service=github

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: B002 "object" is used as an argument and thus shadows a python builtin, consider renaming the argument
test.py:1:23: B002 "list" is used as an argument and thus shadows a python builtin, consider renaming the argument
test.py:1:29: B002 "dict" is used as an argument and thus shadows a python builtin, consider renaming the argument
test.py:2:5: B001 "max" is a python builtin and is being shadowed, consider renaming the variable
test.py:3:5: B001 "min" is a python builtin and is being shadowed, consider renaming the variable
test.py:4:5: B001 "zip" is a python builtin and is being shadowed, consider renaming the variable

Install

Install with pip:

$ pip install flake8-builtins

Requirements

  • Python 2.7, 3.3, 3.4

  • flake8

License

GPL 2.0

Changelog

0.4 (2017-05-29)

  • Use a different code for class attributes. [karamanolev]

0.3.1.post0 (2017-05-27)

  • Release universal wheels, not only python 2 wheels. [gforcada]

  • Update trove classifiers. [gforcada]

0.3.1 (2017-05-27)

  • Fix stdin handling. [sangiovanni]

0.3 (2017-05-15)

  • Handle stdin, which is the way flake8 gets integrated into editors. [gforcada]

  • Test against Python 2.7, 3.5, 3.6 and pypy. [gforcada]

0.2 (2016-03-30)

  • Whitelist some builtins. [gforcada]

0.1 (2016-03-04)

  • Initial release [gforcada]

  • Add buildout and other stuff. [gforcada]

  • Add actual code. [gforcada]

  • Drop support for python 3.3, only python 2.7 and python 3.4 are tested. [gforcada]

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flake8-builtins-0.4.tar.gz (15.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flake8_builtins-0.4-py2.py3-none-any.whl (6.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file flake8-builtins-0.4.tar.gz.

File metadata

  • Download URL: flake8-builtins-0.4.tar.gz
  • Upload date:
  • Size: 15.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for flake8-builtins-0.4.tar.gz
Algorithm Hash digest
SHA256 55e26abbf398e600069882f41166de70372302baaf49985180d1531c47b9932a
MD5 0a81fedfb682343394bdf458f7e00d4d
BLAKE2b-256 89b5dc6cc1ad7afb4147740422e973dfec4d9fb6daa96c87d4045984770aedfc

See more details on using hashes here.

File details

Details for the file flake8_builtins-0.4-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for flake8_builtins-0.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 a6aa6ebf0ea848a3106524352a160b36071870f90e5b1f9d4563479088675f7d
MD5 a3fce256df22631d9e597c7bd7c4e110
BLAKE2b-256 85dd26c694dd6668593db7efeeff05a17651215dd92a3966456f0d77a1e3fecd

See more details on using hashes here.

Release history Release notifications | RSS feed

3.1.0

2 files

3.0.0

2 files

2.5.0

2 files

2.4.0

2 files

2.3.0

2 files

2.2.0

2 files

2.1.0

2 files

2.0.1

2 files

2.0.0

2 files

1.5.3

2 files

1.5.2

2 files

1.5.1

2 files

1.5.0

2 files

1.4.2

2 files

1.4.1

2 files

1.4.0

2 files

1.3.1

2 files

1.3.0

2 files

1.2.3

2 files

1.2.2

2 files

1.2.1

2 files

1.2

2 files

1.1.1

2 files

1.1.0

2 files

1.0.post0

2 files

1.0

2 files

This release

0.4 This release

2 files

0.3.1.post0

2 files

0.3.1

2 files

0.3

2 files

0.2

2 files

0.1

1 file

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