Skip to content

unnecessary-builtin-import (UP029)

Derived from the pyupgrade linter.

Fix is always available.

What it does

Checks for unnecessary imports of builtins.

Why is this bad?

Builtins are always available. Importing them is unnecessary and should be removed to avoid confusion.

Example

from builtins import str

str(1)

Use instead:

str(1)

Fix safety

This fix is marked as unsafe because removing the import may change program behavior. For example, in the following situation:

def str(x):
    return x


from builtins import str

str(1)  # `"1"` with the import, `1` without

References