Skip to content

Files

Latest commit

 

History

History
30 lines (18 loc) · 931 Bytes

wildcard-import.md

File metadata and controls

30 lines (18 loc) · 931 Bytes

Pattern: Use of wildcard import

Issue: -

Description

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)

Further Reading