Skip to content

builtin-attribute-shadowing (A003)#

Derived from the flake8-builtins linter.

What it does#

Checks for any class attributes or methods that use the same name as a builtin.

Why is this bad?#

Reusing a builtin name for the name of an attribute increases the difficulty of reading and maintaining the code, and can cause non-obvious errors, as readers may mistake the attribute for the builtin and vice versa.

Builtins can be marked as exceptions to this rule via the flake8-builtins.builtins-ignorelist configuration option, or converted to the appropriate dunder method. Methods decorated with @typing.override or @typing_extensions.override are also ignored.

Example#

class Shadow:
    def int():
        return 0

Use instead:

class Shadow:
    def to_int():
        return 0

Or:

class Shadow:
    # Callable as `int(shadow)`
    def __int__():
        return 0

Options#

References#