redline
MediumHygienewildcard-import

Wildcard import

Wildcard import. from os.path import * pulls every name in. Readers can't tell where a name came from.

This is how the comment reads inline, under the flagged line.

Why it matters

Star imports hide where names come from, shadow builtins and break when the other module adds a name.

What to do

Import the names you use.

Examples

Flagged
from utils import *
Better
from utils import slugify, parse_date

What it catches

It reads a pattern on each line, aware of strings and comments. Languages: Python. Scope: All files. These cases are the rule's own tests: the first set must be flagged and the second must not.

Flagged

from os.path import *

Left alone

from os.path import join

Research

`from x import *`. Readers cannot tell where a name comes from.

Turn it off or change it

In a config file for the CLI, or in the API's rules field:

{
  "rules": {
    "disable": [
      "wildcard-import"
    ],
    "severity": {
      "wildcard-import": "low"
    }
  }
}

Read the source or report a false positive.