Skip to main content

classify_import_statement

Function classify_import_statement 

Source
pub fn classify_import_statement(statement: &str) -> ImportKind
Expand description

Classify an import statement string as ImportKind::Future, ImportKind::Stdlib, or ImportKind::ThirdParty.

Contract: only the top-level package name of the first module in the statement is examined. This is intentional: the function is called from build_import_edits exclusively with TypeImportSpec::import_statement values, which are always single-module strings such as "from typing import Any" or "import pathlib". Comma-separated multi-module lines (import os, pytest) can never reach this function through that path.

For group classification of raw file lines (the string-fallback parser) the same first-module heuristic is used, matching isort’s own group-assignment behaviour. In practice, mixed-kind lines are a style violation that tools like isort/ruff would split anyway.