Skip to content

fix(source-tree): report only runtime third-party imports - #36

Merged
HaoZeke merged 1 commit into
mainfrom
fix/import-scan
Nov 16, 2026
Merged

HaoZeke merged 1 commit into
mainfrom
fix/import-scan

Conversation

@HaoZeke

@HaoZeke HaoZeke commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator

The import scan of a PyPI source tree reports only runtime third-party imports.

  • The scan turned every import it saw into an undeclared-import judgment residual: standard-library modules, imports in tests/, docs/conf.py, dev/ scripts and setup.py, and words from docstring prose ("from the fastnumbers module" became an import of the). The duplicate check compared by substring, so re was dropped because "undeclared" contains it, and requests was dropped after requests_cache. natsort 8.4.0 got 29 residuals, 3 of them real.
  • Standard-library names come from data/python-stdlib.txt, the union of sys.stdlib_module_names of the Pythons EESSI ships. Packages the Python module installs itself stay off the residual list, as they do for build requirements. The scan covers the package sources and setup.py, so a build import such as Cython is reported. It leaves out test directories, top-level docs, examples, benchmarks and dev directories, conftest.py and noxfile.py. Only import statements outside triple-quoted strings count, duplicates compare by exact name, and the walk is sorted so the evidence path is stable. natsort now gets fastnumbers, icu and typing_extensions.

standard_library_imports_are_not_residuals, test_doc_and_maintainer_imports_are_not_residuals, docstring_prose_is_not_an_import and a_name_inside_a_reported_name_is_still_reported cover those. The commit has a towncrier fragment. Main has no towncrier yet; #26 (fix/towncrier) adds it.

The import scan of a PyPI source tree turned every import it saw into
an undeclared-import judgment residual: standard-library modules,
imports in tests/, docs/conf.py, dev/ scripts and setup.py, and words
from docstring prose ("from the fastnumbers module" became an import
of `the`). The duplicate check compared by substring, so `re` was
dropped because "undeclared" contains it, and `requests` was dropped
after `requests_cache`. natsort 8.4.0 got 29 residuals, three of them
real.

Standard-library names come from data/python-stdlib.txt, the union of
sys.stdlib_module_names of the Pythons EESSI ships, and the packages
the Python module installs itself are skipped as they are for build
requirements. Test directories, top-level docs, examples, benchmarks
and dev directories, conftest.py and noxfile.py are not scanned;
setup.py still is, so a build import such as Cython is reported. Only
import statements outside triple-quoted strings count, duplicates
compare by exact name, and the walk is sorted so the evidence path is
stable. natsort now gets fastnumbers, icu and typing_extensions.
@HaoZeke
HaoZeke merged commit 5cf92c0 into main Nov 16, 2026
21 checks passed
@HaoZeke
HaoZeke deleted the fix/import-scan branch November 16, 2026 05:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant