#3888·graphify

[Bug]: Python: a class used in a type annotation turns calls to its constructor into no edge at all (0.9.62+)

Author: wpoPRCreated Sep 28, 2026Updated Sep 28, 2026

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 Parser in the file. In extractors/engine.py the in-file resolution binds Parser() to that stub. Then neither branch runs, so the call is emitted neither as an edge nor as a raw call:

    python
    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 resolution

    Before #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-file calls and the generic references collapsed in build (_GENERIC_RELATIONS, specific beats generic).

Steps to reproduce

bash
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 below

Suggested 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:

    diff
    -                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 a calls, which build then collapses. We tried this (a generic_only_pairs set checked next to existing_pairs in the direct-call branch). It recovers the other 36, but it is wider than the regression: it also turns 223 long-standing uses/references pairs into calls. 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.