Skip to content

Avoid Builtin Shadow

Sourcery comment id: avoid-builtin-shadow


Don't assign to builtin variables, such as list.


list = [1, 1, 2, 3, 5, 8]

Possible Fix

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 list, getattr, and type (See 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.