Repository navigation
Call resolver: typed step — resolve x.method() when the function shows x's class (Python) - #3693
Merged
Merged
Conversation
…shows (python) `app = FastAPI()` ... `app.post(...)` was a `receiver` guess: the resolver knew only the receiver's name, and several classes define post. The detector now records, per function, receiver -> class from local evidence (a constructor assignment, incl. self.attr; a parameter or assignment annotation; `with Cls() as x`), for the receivers the function calls methods on. A receiver with conflicting evidence, a non-call assignment or a `for` binding is left out. The resolver's new `typed` step (scoped) takes that class's method, or its nearest ancestor's, when the class is one the scan knows -- a factory function's name changes nothing. Persisted as function_data.calls_out_receiver_types (JSON object, healed into older DBs) and restored by the state rehydrator, so a delta scan resolves the same way. call_graph_resolution.py now derives its confident steps from the resolver. call_graph_resolution.py python (pyan3): confident precision 99.3 -> 99.4 (1687 -> 1803 judged), recall 48.0 -> 51.3, resolution recall 90.2 -> 96.9. Golden masters: no drift in either fixture. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01GCpfMCUMpco98QGbsuv2sr
Contributor
typed step for receivers whose class the function …typed step — resolve x.method() when the function shows x's class (Python)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
A Level 2 (call-graph resolution, epic #3265) improvement.
Problem. After #3689/#3690, most of the remaining named-but-unlinked Python edges were
receiverguesses:x.method()where several classes definemethod, and the resolver knows only the receiver's name. A breakdown of those misses against pyan3 on language-crucible:x = SomeClass(...)in the same functionapp = FastAPI()…@app.post("/")→FastAPI.postself.channelfor attr in ...: attr.declare(), honestly ambiguousFix.
Detector (
_python_receiver_types, Python and embedded_python via a top-levelcalls_out_receiver_typesprofile flag; not arulespattern, per orphaned_logic reports 100% dead code for five languages whose invocation model never names the callee — the family #2727 closed without covering #2806): records, per function, receiver → class for the receivers the function calls methods on. Evidence:self.attr = mod.Parser(...);ch: Channel,x: Store = make());with Session() as s.A receiver is left out when its evidence conflicts, when it's also assigned from a non-call, or when it's bound by a
for. It's never guessed.Resolver: a new
typedstep, scoped (confident). It tries that class's method, then the nearest ancestor that has one, using the same lookupself.method()uses. It applies only when the name is a class the scan knows, soapp = create_app()(a factory) changes nothing.Persistence: new
function_data.calls_out_receiver_typescolumn (a JSON object, healed into older DBs). The state rehydrator restores it, so a delta scan resolves exactly like a fresh one.tests/tools/call_graph_resolution.pynow derives its confident steps from the resolver'sRESOLUTION_OF_STEPinstead of a hand-kept list.docs/function_call_graph.mdgains thetypedrow, and its example reachability query includes the step.Type of change
detector.py,call_resolver.py,record_keeper.py,state_rehydrator.py, python profiles)Measured:
call_graph_resolution.py python(pyan3 reference, language-crucible)No new "wrong target" examples appear in the 20-sample list.
tests/call_graph_resolution_baseline.jsonis regenerated.Cumulative since this Level 2 work started: precision 98.7% → 99.4%, edge recall 36.1% → 51.3%, resolution recall 71.8% → 96.9%.
Golden masters
crucible_check.py --mode both --update --yes: no drift in either fixture. The new links are function→function, between files that already import each other, so no file-level metric moves.Tests
tests/extraction/languages/test_calls_out_receiver_types.pycovers:self.attr, annotation andwithevidence;for-bound receivers are dropped;==and+=aren't evidence;tests/core_engine/test_call_resolver.py: thetypedstep, an inherited method, and a non-class type (factory) changing nothing.tests/tools_recorders/test_fcall_data.py: the column persists and rehydrates.Verification
Not in this PR: the same idea for
const x = new Foo()/Foo x = new Foo()in JS/TS/Java/C#. That's deferred until a Level 2 reference exists for one of those languages to measure it against.🤖 Generated with Claude Code
https://claude.ai/code/session_01GCpfMCUMpco98QGbsuv2sr