Skip to content

Python: a quoted forward-reference annotation (o: "Alpha") drops the call edge that the identical unquoted annotation resolves #1684

Description

@inth3shadows

Summary

Python: a parameter annotated with a string (forward-reference) annotationdef f(o: "Alpha") — loses receiver-type resolution that the identical unquoted annotation gets. The method call produces no calls edge at all.

Quoted annotations are ordinary Python (forward references, and everything under from __future__ import annotations), so this silently drops real edges in normal code.

Environment

@colbymchenry/codegraph 1.5.0 and 1.6.0 (npm latest), Linux, fresh codegraph init per version.

Repro

# pkg/a.py
def render(x):
    return x


class Alpha:
    def render(self):
        return "a"


class Beta:
    def render(self):
        return "b"
# pkg/b.py
from .a import Alpha


def quoted(o: "Alpha"):
    return o.render()      # -> NO EDGE

def bare(o: Alpha):
    return o.render()      # -> calls Alpha.render (pkg/a.py:6)

Observed — identical on 1.5.0 and 1.6.0

caller   target                    line
bare     render @pkg/a.py:6          9
(quoted produces no row at all)

Same file, same call expression, same class — only the quoting of the annotation differs.

Note on the trigger

The miss needs a competing same-named method to be present: with only Alpha.render (plus the top-level render) in the tree, the quoted form still resolved. Adding Beta.render is what makes the quoted form drop out while the bare form keeps resolving. So the quoted annotation appears not to establish the receiver type, leaving the call to name matching, which then declines under the extra candidate.

codegraph callers render correspondingly under-reports: quoted never appears.

Verification

Reproduced on both versions with a fresh index each time. Controls in the same run: the unquoted form resolves, and in a two-candidate variant of the same fixture the quoted form resolves — so this is the quoting interacting with candidate count, not a blanket annotation failure.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions