Skip to content

fix(python): resolve self.<attr>.<method>() calls through the attribute's class - #4176

Closed
Mpasha17 wants to merge 1 commit into
Graphify-Labs:v8from
Mpasha17:fix/python-self-attr-calls-2860
Closed

Mpasha17 wants to merge 1 commit into
Graphify-Labs:v8from
Mpasha17:fix/python-self-attr-calls-2860

Conversation

@Mpasha17

@Mpasha17 Mpasha17 commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Closes #2860

Calls like self.agents.bull_researcher(idea) got no calls edge, since nothing tracked what self.agents was. Now each class gets a small field -> class table from its methods: self.X = Ctor(...) (bare capitalized name), self.X: T annotations, with self.X = None ignored. A field that gets two different classes or some other value (factory(), tuple unpack) stays untyped.

_resolve_python_member_calls then adds an INFERRED edge only when the class name matches exactly one class, that class is defined in or imported by the caller's file, and it defines the method itself. Otherwise no edge, so from requests import Session won't bind to an unrelated local Session.

Not covered: inherited methods, fields set in a parent class, self.x = mod.Ctor(), the outer name in self.a = self.b = Ctor(), and calls inside a nested def.

@sai2142 I saw you'd prototyped a fix. If you already have one going, I'm happy to close this.

Testing: 4 new tests in tests/test_extract.py (same file, across an import, annotation, and a negative case); the 3 positive ones fail on v8. Full suite on 3.10/3.12/3.13/3.14 shows the same failures as v8, ruff clean, no new pyright findings. Live graphify update --no-cluster on the issue repro adds deep_portfolio_review -> AgentRunner.bull_researcher. On httpx, urllib3, requests and click it added 12 edges, all checked by hand and correct, and removed none.

AI-assisted (Grok Bot); each commit carries a Co-Authored-By line.

@Mpasha17
Mpasha17 requested a review from safishamsi as a code owner October 7, 2026 03:43
@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown

Thanks for the pull request, @Mpasha17. 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.10 and 3.13, and that the change keeps extraction deterministic.

@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 reviewed this change.

Worth a look — the grounded gate found no coupling regressions or blocking issues, but 1 advisory finding(s) below merit a look before merge.

Formal verification. PR-changed functions: 0/2 verified (0 proven, 0 may-equivalent, 0 distinguished) · 2 not verified (1 vacuous, 1 unsupported).

Not verified on this run: \_resolve\_python\_member\_calls (vacuous: never exercised), \_extract\_generic (unsupported).


Graphify review — findings

Resolves Python self.X.m() calls by typing self.X per class from its assignments across that class's methods, using either an annotation (self.x: T = ...) or a bare constructor (self.x = Ctor()). Conflicting or untypable bindings leave the field untyped, and self.x = None is ignored. A call emits an INFERRED calls edge (score 0.85) only when the type names a single class that the caller's file defines or imports and that class owns m; otherwise no edge is added, so a same-named method on another class is never targeted.

Worth a look

  • Typed self.X.m() calls skip the existing receiver-resolution fallback — graphify/extract.py:4247 · Escalate · medium
    • agreed by 2 of 2 members but NOT verified (no proof, no reproducing execution) — consensus is not a verdict; needs human review
Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 3083 functions depend on the 1051 functions this change touches.

Health — this change adds coupling hotspots:

  • new: extract() — 789 callers, 50 callees
  • new: _rebuild_code() — 151 callers, 56 callees
  • new: _extract_generic() — 18 callers, 33 callees
  • new: extract_js() — 87 callers, 5 callees
  • new: extract_xaml() — 19 callers, 17 callees
  • new: main() — 102 callers, 3 callees
  • new: extract_objc() — 27 callers, 10 callees
  • new: dispatch_command() — 2 callers, 128 callees
  • …and 49 more — each is listed as a finding

Verification — 3083 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

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

Advisory (not blocking):

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

Test selection

Test selection

148 of 337 test file(s) selected (44%) via static blast radius.

  • tests/test_astro_extraction.py — impact
  • tests/test_astro_import_ids.py — impact
  • tests/test_blade_extractor.py — impact
  • tests/test_build.py — impact
  • tests/test_builtin_global_type_refs.py — impact
  • tests/test_cache.py — impact
  • tests/test_case_sensitive_resolution.py — impact
  • tests/test_cjs_module_extension.py — impact
  • tests/test_cobol_extractor.py — impact
  • tests/test_cpp_method_declarations.py — impact
  • tests/test_cpp_nested_and_cli.py — impact
  • tests/test_cpp_objc_cross_file_calls.py — impact
  • tests/test_cross_extension_reexport_self_cycle.py — impact
  • tests/test_cross_language_call_resolution.py — impact
  • tests/test_cross_repo_external_call_guards.py — impact
  • tests/test_cross_repo_member_calls.py — impact
  • tests/test_csharp_call_site_generic_args.py — impact
  • tests/test_csharp_enum_members.py — impact
  • tests/test_csharp_field_generic_args.py — impact
  • tests/test_csharp_generic_callsites.py — impact
  • tests/test_csharp_interface_dispatch.py — impact
  • tests/test_csharp_member_calls.py — impact
  • tests/test_csharp_member_nodes.py — impact
  • tests/test_csharp_object_creation.py — impact
  • tests/test_csharp_partial_classes.py — impact
  • tests/test_csharp_tuple_type_refs.py — impact
  • tests/test_csharp_type_resolution.py — impact
  • tests/test_definition_file_portability.py — impact
  • tests/test_detect.py — impact
  • tests/test_dotnet.py — impact
  • tests/test_duplicate_annotation_edges.py — impact
  • tests/test_elixir_import_resolution.py — impact
  • tests/test_elixir_unqualified_call_scope.py — impact
  • tests/test_erlang_extractor.py — impact
  • tests/test_extract.py — impact, changed-test
  • tests/test_extract_cache_location.py — impact
  • tests/test_extract_php_closures.py — impact
  • tests/test_file_label_disambiguation.py — impact
  • tests/test_file_node_id_spec.py — impact
  • tests/test_forwarding_review_findings.py — impact
  • tests/test_go_builtin_call_targets.py — impact
  • tests/test_go_import_repoint.py — impact
  • tests/test_go_interface_methods.py — impact
  • tests/test_go_qualified_resolution.py — impact
  • tests/test_import_extension_resolution.py — impact
  • tests/test_import_self_loops.py — impact
  • tests/test_imported_export_forwarding.py — impact
  • tests/test_incremental.py — impact
  • tests/test_indirect_call_arrow_single_param_shadow.py — impact
  • tests/test_indirect_call_block_scoped_shadow.py — impact
  • … and 98 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.

Formal verification

Could not verify: Could not verify \_resolve\_python\_member\_calls.

The verifier did not have enough to check \_resolve\_python\_member\_calls, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: non-vacuity: domain too small (only 1 distinct inputs exercised, need 3) — 'no divergence' would be near-vacuous

Could not verify: Could not verify \_extract\_generic.

The verifier did not have enough to check \_extract\_generic, so it is saying so rather than guessing. No false assurance is the whole point.

Guarantee: No guarantee either way, this is an honest abstention, not a pass.

Note: Reason: no capturable inputs from the test suite; property tier: parameter `config` is annotated `LanguageConfig` — outside the synthesizable primitive/collection set

· 57 more finding(s) on lines outside this diff (see the check run).

@Mpasha17

Mpasha17 commented Oct 7, 2026

Copy link
Copy Markdown
Contributor Author

Checked this one and it doesn't skip anything v8 did. A self.X.m() call never gets a receiver captured (Python's self is a plain identifier), so on v8 these calls already hit if not receiver ...: continue in this same loop, and nothing parks Python calls into unresolved_calls. I compared v8 against this branch on repros where the typed path fails (inherited method, method not on the class, duplicate class, class not imported) and on httpx/urllib3/requests/click: the only differences are the added edges. Nothing was removed and unresolved_calls didn't change.

safishamsi pushed a commit that referenced this pull request Oct 7, 2026
…ound local (#4198)

Resolves a call on a local or parameter whose class is known from an annotation
(c: Client), an Optional/union/string annotation, or a constructor/with binding,
to the owning class's method - fail-closed to a single in-file-or-imported class
that owns the method. Complements the self.<attr> arm from #4176.

Rebased onto the landed #4176: reuses its _emit_call(inferred=True) INFERRED/0.85
path instead of the PR's own confidence= parameter.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Already shipped — landed via authorship-preserving cherry-pick (commit a061e0b, released). Thank you, @Mpasha17!

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.

Python: no receiver-type inference for self.<attr>.<method>() — 33 live methods reported as dead code

2 participants