Skip to content

Python package imports (from pkg import X) never draw an edge to pkg/__init__.py #3545

Closed

Description

@squid-protocol

Problem

from fastapi import FastAPI binds the package fastapi, i.e. fastapi/__init__.py, but the engine draws no dependency edge for it. Package __init__.py files are often a project's re-export hub, so they are undercounted in the import graph: popularity, PageRank and blast radius. So is everything that reaches the package's public API only through them.

Measured

Python, language-crucible v1.5.0 (data/python, 259 files). Engine edge_data was compared with edges built from Python's ast module, resolving imports to files present in the corpus.

  • AST edges: 492. Engine edges: 326. In both: 285. Recall is about 58%.
  • 198 of the 207 missed edges are this one shape: a file in fastapi/tests/ importing from fastapi import ..., which targets fastapi/fastapi/__init__.py. The other 9 are scattered (tests/utils.py 5, params.py 2, and single cases).
  • Without this shape, recall on the remaining edges is about 97%.

Example: fastapi/tests/test_security_http_base.py line 1 is from fastapi import FastAPI, Security. The engine draws no edge to fastapi/fastapi/__init__.py. Its only edge from that file is a false one, from fastapi.security.http to twisted/http.py (tracked separately).

Likely mechanism (to confirm)

network_risk_sensor.py resolves a token by full path, then by filename or stem. The token fastapi has no file whose stem is fastapi; the file is fastapi/__init__.py, whose stem is __init__. So nothing matches. The resolution map has no key that maps a package directory to its __init__.py.

Fix direction

  • When building the resolution map for Python, also key each __init__.py by its directory's dotted path and name, e.g. fastapi and fastapi/fastapi, so a package token resolves to it.
  • Keep it Python-scoped, and check the interaction with the dotted-import false-edge fix (filed alongside this one). A package key must not become a new lone-stem fallback.
  • Re-bless the golden masters. Python __init__.py PageRank should rise corpus-wide.

Activity

  1. added
    bug
    core-engine
    on Sep 25, 2026
  2. squid-protocol commented on Sep 25, 2026

    @squid-protocol
    OwnerAuthor

    Fixed by #3562 (merged). A Python package import now binds to its __init__.py, and module paths resolve under source roots. Tests: tests/security_auditing/test_import_resolution_by_language_rule.py. import_graph_accuracy.py now reports Python at 98.9% precision and 97.9% recall, and CI gates that number.


    Generated by Claude Code

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

    bugcore-engine

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions