[Bug]: Python: a class used in a type annotation turns calls to its constructor into no edge at all (0.9.62+)
What happened?
Since 0.9.62, calling a project class whose name also appears in a type annotation in the same file drops the
calls edge to its constructor. 0.9.61 and older resolve it. Still reproduces on 0.9.70 and on v8@4c21b15e9b.
Two shapes, same root:
A. annotation in another function: the annotation leaves a sourceless stub node
Parserin the file. Inextractors/engine.pythe in-file resolution bindsParser()to that stub. Then neither branch runs, so the call is emitted neither as an edge nor as a raw call:external_stub_target = bool(tgt_nid and not nid_to_sf.get(tgt_nid)) if tgt_nid and not external_stub_target: ... # emits calls elif callee_name and not tgt_nid: ... # raw_call for cross-file resolutionBefore #3156 the edge to the stub was emitted and later remapped to the real class.
B. annotation in the same function (
def detect(self) -> Parser: return Parser()): even when the call reaches the cross-file pass, it is skipped because the pair already has the annotation edge:if tgt != caller and (caller, tgt) not in existing_pairs:(extract.py). Before, the in-filecallsand the genericreferencescollapsed in build (_GENERIC_RELATIONS, specific beats generic).
Steps to reproduce
mkdir -p repro/app/engines/transcript && cd repro
touch app/engines/__init__.py app/engines/transcript/__init__.py
cat > app/engines/transcript/parser.py <<'EOF'
class Parser:
def feed(self, line):
return line
EOF
cat > app/engines/engine.py <<'EOF'
from typing import Optional
from engines.transcript.parser import Parser
class Engine:
def detect(self): # shape A
return Parser()
def get_parser(self) -> Optional[Parser]:
return None
def make(self) -> Parser: # shape B
return Parser()
EOF
git init -q . && graphify update .Error output or graph output
edges from app/engines/engine.py
0.9.57, 0.9.61: calls .detect()->Parser; calls .make()->Parser; references .get_parser()->Parser
0.9.62, 0.9.70: references .get_parser()->Parser; references .make()->Parser <- both calls lost
0.9.70 + shape-A fix: calls .detect()->Parser; references .get_parser(); references .make()
0.9.70 + shape-A + B fixes: calls .detect()->Parser; calls .make()->Parser; references .get_parser()
controls: no annotation -> calls on every version;
external class (fastapi.HTTPException) annotated + called -> only references on 0.9.62+ (the #3156
intent), unchanged by the patches belowSuggested fix, measured on 0.9.70:
Shape A, one line in
extractors/engine.py: let a call bound to a sourceless stub fall through to cross-file resolution, where the #3156 guard still drops truly external targets:- elif callee_name and not tgt_nid: + elif callee_name and (not tgt_nid or external_stub_target):Restores shape A (12 of 48 lost constructor edges in our repo). External-class control unchanged.
Shape B: a pair that has only generic edges (
references/uses/mentions) should not block acalls, which build then collapses. We tried this (ageneric_only_pairsset checked next toexisting_pairsin the direct-call branch). It recovers the other 36, but it is wider than the regression: it also turns 223 long-standinguses/referencespairs intocalls. We checked all of them by AST and each one is a real call site, so it looks correct, but it is a behavior change beyond 0.9.61. Leaving that decision to you.
Version: 0.9.62 → 0.9.70 (last good: 0.9.61) · OS: macOS · Python: 3.11 · Install: uv (clean fixture, no LLM backend)
Additional context: introduced alongside #3156 (0.9.62). Not covered by #3405 or #2447.
Source: Graphify-Labs/graphify