Pattern: Use of wildcard import
Issue: -
Wildcard imports (from <module> import *
) should be avoided, as they make it unclear which names are present in the namespace, confusing both readers and many automated tools. Although certain modules are designed to export only names that follow certain patterns when you use import *
, it is still considered bad practice in production code.
Make the import statement more specific or import the whole module depending on your needs.
Example of incorrect code:
from math import * # [wildcard-import]
result = math.trunc(123.45)
Example of correct code:
from math import trunc
result = math.trunc(123.45)