You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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.8, 3.9, 3.10, 3.11, 3.12, 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
About
Check for python builtins being used as variables or parameters