Skip to content

Import builder resolves bare to a same-stem local module (captures stdlib) #4261

Closed

Description

@waynegault

Summary

graphify's import-graph builder resolves a bare import <name> to a local module that shares the same stem, which captures stdlib imports as if they pointed at local files.

Repro

In a repo with a file at pipeline/common/logging.py (any module whose stem collides with a stdlib top-level name), a bare import logging anywhere in the tree is recorded as an edge whose target resolves to that local pipeline/common/logging.py, not to stdlib logging.

Measured on one real corpus before we worked around it:

  • logging: 853 edges landed on pipeline/common/logging.py
  • types: 60 edges → pipeline/common/types.py
  • io: 9 edges → pipeline/common/io.py
  • total 922 fabricated stdlib→local edges

Why it's wrong

A bare import resolves from sys.path, so a module nested under the repo root can never be its target. The result is a fabricated import cycle and logging.py becoming the graph's top hub.

Suggested fix

Prefer a real path/package match over a bare-stem match when resolving an import target. The local workaround we currently carry is a post-extraction filter (filter_stdlib_name_collision_edges), which we'd like to delete once upstream resolves bare-stem imports correctly.

Reported by a downstream consumer of the graphify CLI (pipx graphifyy).

Activity

  1. github-actions commented on Oct 9, 2026

    @github-actions

    Thanks for opening this issue, @waynegault. A maintainer will take a look soon.

    If you would like to discuss it in real time, come say hi on our Discord server. For longer-form questions and ideas there is also GitHub Discussions.

    To help us triage, please make sure the report includes what you expected, what actually happened, and the steps (and a small sample) to reproduce it.

  2. safishamsi commented on Oct 10, 2026

    @safishamsi
    Member

    Fixed in 0.9.84 (now on PyPI). A bare import logging is no longer captured by a loose same-named module (scripts/logging.py) in a non-package directory; it resolves to the stdlib module. The guard uses a vendored, deterministic stdlib-name set (not the host's live sys.stdlib_module_names, so extraction stays reproducible across machines and interpreter versions) and is applied at the module resolver, the sibling-repoint pass, and the build-time stem-alias index. A deliberate package shadow (logging/__init__.py) still resolves. Thanks, @waynegault.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions