Avoid Builtin Shadow¶
Sourcery comment id:
Don't assign to builtin variables, such as
list = [1, 1, 2, 3, 5, 8]
fibonacci = [1, 1, 2, 3, 5, 8]
Python has a number of
builtin variables: functions and constants that form a
part of the language, such as
https://docs.python.org/3/library/functions.html). It is valid, in the language,
to re-bind such variables:
list = [1, 2, 3]
However, this is considered poor practice.
- It will confuse other developers.
- It will confuse syntax highlighters and linters.
- It means you can no longer use that builtin for its original purpose.
How can you solve this?
Rename the variable something more specific, such as
integers. In a pinch,
my_list and similar names are colloquially-recognized placeholders.