Skip to content

Python: AST extractor misses ~53% of Python class inheritance edges (cross-file base classes) #2736

Open

Description

@oskbjo

When a Python class inherits from a base class imported from another file, the AST extractor fails to emit an inherits edge. Instead it produces a weaker uses [INFERRED] edge pointing at the import line rather than the class definition.

Repro:

  # module_a.py
  class BaseDriver:
      ...
  # module_b.py
  from module_a import BaseDriver

  class ChildDriver(BaseDriver):  # <-- should produce inherits [EXTRACTED]
      ...

Actual: ChildDriver --uses [INFERRED]--> BaseDriver (at import line)
Expected: ChildDriver --inherits [EXTRACTED]--> BaseDriver (at class def line)

Same-file inheritance is handled correctly. The issue is that the extractor doesn't resolve imported names back to their class node when the base class comes from another module.

Measurement on a ~900-file Python codebase:

  • 820 inheritance relationships found via ast.ClassDef.bases
  • 389 (47%) correctly emitted as inherits edges (same-file or simple cases)
  • 431 (53%) missing, represented only as uses [INFERRED]

Impact:

  • graphify path between parent and child classes routes through unrelated intermediate nodes instead of showing the direct inheritance chain
  • Community detection separates parent/child classes that should cluster together
  • Driver/plugin hierarchies with deep cross-file inheritance chains are especially affected

Environment: graphify 0.9.42, Python 3.12, Windows

Activity

  1. NithishKumar04 commented on Aug 14, 2026

    @NithishKumar04
    Contributor

    I reproduced this on current v8 and traced it through final graph construction. The extracted inherits [EXTRACTED] edge is overwritten by a later uses [INFERRED] edge. Aliased imports and duplicate class names also need exact import-aware resolution.

    I am preparing a focused fix with raw-extraction, built-graph, ambiguity, alias, and incremental regression coverage. I checked the overlapping #1231 and #2684 work and will keep this change compatible rather than duplicating their scope.

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