Skip to content

deprecated-import

Pythonstyleno fixdefault: offpython/ruff

Reports an import of a name from the wrong module for the target_version: a name of typing_extensions that typing, collections.abc or warnings has in that version, an alias in typing of a collections.abc class, or List, Dict, Set, FrozenSet, Tuple or Type.

The backport module exists for old versions. Once the standard library has the name, importing it from there removes a dependency, and the old aliases of typing are deprecated in favour of the builtin generics and collections.abc.

To fix, import the name from the module that the message names.

Reported
...
from typing import Optional
...
from typing import List
...
from typing import Generator
...
...
import datetime
...
from typing_extensions import Self
import sys
...
python:
lint:
rules:
deprecated-import: warn # off (default), warn, error

Enabled by the presets: python/ruff.

Suppress one line with sudsy-disable-next-line deprecated-import in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
ruff UP035 full