Skip to content

fix(python): emit inherits for parameterized bases and walk them for inherited calls - #5318

Open
Synvoya wants to merge 1 commit into
Graphify-Labs:v8from
Synvoya:fix/python-parameterized-base-inherits-v2
Open

Synvoya wants to merge 1 commit into
Graphify-Labs:v8from
Synvoya:fix/python-parameterized-base-inherits-v2

Conversation

@Synvoya

@Synvoya Synvoya commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Re-submission of #1815, rebased onto current v8 (340268a), which supersedes it. It is extended for the cross-file inherited-method walk and its python_opaque_bases marker (86e3c1d), which landed on v8 after the original PR.

class Repo(Base[int]) emitted no inherits edge: the Python heritage handler only accepted identifier bases, and a parameterized base parses as a subscript whose value field is the base. On current v8 the same class is also marked python_opaque_bases, so self.m() in Repo never reaches Base.m in another file, although Base is in its MRO exactly as for class Repo(Base).

A new helper, _python_base_name_node(), now decides both: it unwraps a subscript to its value and accepts an identifier. A subscript of a dotted name, a call, or any other expression stays opaque and gets no edge. Generic arguments never become parents.

Type of change

  • Bug fix

Verification & Invariants

Invariant: the inherits edges and the opaque-bases marker agree. A base gets an edge exactly when the walk may trust it, so the walk neither stops at a base it can see nor follows one it cannot.

  • test_python_parameterized_base_inherits_edge: Base[int], Mixin, Base[list[str]] and a dynamic base factory; no edges to list, str or the factory.
  • test_a_parameterized_base_is_walked_like_a_bare_one: cross-file self.m() through Base[int]. It fails with the edge fix alone (the class was still opaque).
  • The existing test_chains_the_walk_cannot_order_emit_no_edge still passes: class Generic_(Base, Generic[T]) now has two bases, and the walk stops at two or more as before.

Limitations:

  • Generic[T] and Protocol[T] bases now emit inherits edges to Generic/Protocol name nodes, the same as a bare Protocol base already does.

  • mod.Base[T] is still opaque, like mod.Base.

  • Cached Python extractions need a schema bump to pick this up. I left _AST_CACHE_SCHEMA alone, since recent fixes have it folded into your combined bump; happy to add it here instead.

  • Read the CONTRIBUTING.md guide.

  • Reproduced the issue and identified the invariant.

  • Made the smallest fix necessary.

  • Added a regression test (if bug fix) or isolated boundary test.

  • Kept the PR description synchronized with the final implementation.

  • Documented any limitations / unsupported cases explicitly.

How was this tested?

Python 3.11.16 on macOS, environment from uv sync --all-extras, branch based on v8 340268a.

pytest tests/test_languages.py tests/test_python_inherited_method_calls.py
    # with the fix: 535 passed
    # with engine.py reverted: 2 failed (test_python_parameterized_base_inherits_edge, test_a_parameterized_base_is_walked_like_a_bare_one)
pytest tests -q                        # v8: 11548 passed, 165 skipped, 1 xfailed; this branch: 11550 passed, same skips, 0 failed
ruff check .                           # All checks passed
pyright                                # 759 errors on v8 and on this branch; same set, none new (compared ignoring line numbers)

Graphify-specific checklist

  • I updated generated skill artifacts (uv run python -m tools.skillgen --bless) when changing their source fragments. (No skill sources touched.)
  • I confirmed that AST/structural extraction remains deterministic (no ambient state dependencies like ENV variables).
  • I reviewed changes for security implications (no unsafe interpolation into shell/Python).
  • I confirmed no API keys or local-only graph data are included.
  • (If applicable) I disclosed AI authorship in my commit messages.

AI disclosure: drafted with help from Claude Code and reviewed before posting; the commit carries a Co-Authored-By trailer.

…inherited calls

`class Repo(Base[int])` emitted no `inherits` edge: the Python heritage
handler only accepted `identifier` bases, and a parameterized base parses as
a `subscript` whose `value` field is the base. The same class was also marked
`python_opaque_bases`, so a `self.m()` in `Repo` never reached `Base.m` in
another file, although `Base` is in its MRO exactly as for `class Repo(Base)`.

`_python_base_name_node()` now decides both: it unwraps a subscript to its
value and accepts an identifier. A subscript of a dotted name, a call or any
other expression stays opaque and gets no edge. Generic arguments never
become parents.

Tests: parameterized, nested and mixed bases plus a dynamic base factory in
test_languages.py, and a cross-file `self.m()` through `Base[int]` in
test_python_inherited_method_calls.py; both fail without the change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Synvoya
Synvoya requested a review from safishamsi as a code owner November 18, 2026 13:59
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @Synvoya. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.11 and 3.13, and that the change keeps extraction deterministic.

@github-actions github-actions Bot added the contributor Pull request from a returning community contributor label Nov 18, 2026

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify code review View in Graphify

Review completed · 11561d4bb6f3

Tip

Merge confidence: 5/5 · Looks safe to merge · 🟠 High impact
No issues reported

Parameterized Python bases now produce inherits edges to the named base, and are no longer marked opaque for inherited-method traversal.

Full summary

Parameterized Python bases now produce inherits edges to the named base, and are no longer marked opaque for inherited-method traversal. The added tests cover inheritance extraction and calls through an imported parameterized base.

Code graph and static checks · 4799 functions depend on this change

Impact & health

Impact — 4799 functions depend on the 1213 functions this change touches.

Health — this change adds coupling hotspots:

  • worse: walk() — 1 callers, 100 callees

Formal checks — 4799 functions this change can affect weren't formally checked in this review. Formal checks are informational only.

Gate & verification

✅ PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 3176 function(s) in the blast radius were not formally verified this run

Test selection

52 of 593 test file(s) selected (9%) via static blast radius.

  • tests/test_4992_ts_import_types.py — impact
  • tests/test_astro_extraction.py — impact
  • tests/test_build.py — impact
  • tests/test_cjs_module_extension.py — impact
  • tests/test_cpp_alias_member_resolution.py — impact
  • tests/test_cpp_conditional_initializers.py — impact
  • tests/test_cpp_inherited_member_resolution.py — impact
  • tests/test_cpp_nested_and_cli.py — impact
  • tests/test_csharp_extension_calls.py — impact
  • tests/test_csharp_extension_metadata.py — impact
  • tests/test_csharp_extension_resolution.py — impact
  • tests/test_csharp_partial_classes.py — impact
  • tests/test_dart.py — impact
  • tests/test_dart_typedef.py — impact
  • tests/test_dotnet.py — impact
  • tests/test_ejs_extractor.py — impact
  • tests/test_ext_tagged_id_clash.py — impact
  • tests/test_extract.py — impact
  • tests/test_extract_php_closures.py — impact
  • tests/test_import_extension_resolution.py — impact
  • tests/test_indirect_call_block_scoped_shadow.py — impact
  • tests/test_indirect_dispatch.py — impact
  • tests/test_indirect_dispatch_assign_return.py — impact
  • tests/test_indirect_dispatch_getattr.py — impact
  • tests/test_java_member_calls.py — impact
  • tests/test_java_nested_type_identity.py — impact
  • tests/test_js_exported_scalar_bindings.py — impact
  • tests/test_js_member_collisions.py — impact
  • tests/test_languages.py — impact, changed-test
  • tests/test_multilang.py — impact
  • tests/test_php_unparsed_casts.py — impact
  • tests/test_python_inherited_method_calls.py — impact, changed-test
  • tests/test_python_injected_factory_calls.py — impact
  • tests/test_python_property_reads.py — impact
  • tests/test_python_pytest_fixture_receivers.py — impact
  • tests/test_python_subscript_type_refs.py — impact
  • tests/test_python_underscore_resolution.py — impact
  • tests/test_rationale.py — impact
  • tests/test_ruby_resolution.py — impact
  • tests/test_scala_context_bounds.py — impact
  • tests/test_scala_extension_methods.py — impact
  • tests/test_scala_given_instances.py — impact
  • tests/test_scala_self_type.py — impact
  • tests/test_scala_top_level_binding.py — impact
  • tests/test_scala_type_definition.py — impact
  • tests/test_svelte_extraction.py — impact
  • tests/test_swift_computed_properties.py — impact
  • tests/test_swift_protocol_requirements.py — impact
  • tests/test_trailing_newline_not_a_syntax_error.py — impact
  • tests/test_ts_new_expression_calls.py — impact
  • … and 2 more

Selection is safe under the controlled-regression assumption; always-run tests + a periodic full run are the backstops. Advisory — it never changes the check verdict.

Every flagged function

  • walk() in graphify/extractors/engine.py:7916 · 1 callers, 100 callees: fans out to 100 callees (efferent coupling)

This branch has not been deployed

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

Labels

contributor Pull request from a returning community contributor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant