fix(resolver): R3 — conditional self.X assignment + class-level union types#1
Merged
Conversation
…s (R3) Backend-facade pattern was opaque to the resolver: when a class declared `self._backend` via either `if/else` branches in __init__ or a class- level union annotation (`_b: Foo | Bar`), `self._backend.method()` calls had no way to bind to the concrete backend class. This change extends `_collect_class_attr_types` to: * parse class-level annotations as a list of types (BinOp `A | B` or `Union[A, B]` flatten into operands) * walk `__init__` for `self.X[: T] = Y(...)` assignments, including inside `if/else` (and try/with/for/while) branches, collecting annotation-or-constructor types from every branch The resolver now exposes a `_try_multi_self_attr` helper that emits one CALLS edge per candidate type when `self.X.tail` resolves to multiple classes. Single-type cases still go through the existing R2 path. attr_types schema migrated from dict[str, str] to dict[str, list[str]] with back-compat handling in the resolver (legacy single-string values are still accepted).
8 fixture-based tests for resolver R3: * if/else with two annotated types -> both methods get edges * if/else with same annotation -> annotation wins over RHS constructor * class-level `Foo | Bar` -> both methods get edges * class-level `Union[Foo, Bar]` -> both methods get edges * if/else without annotation -> falls back to RHS constructor names * single-branch annotated assignment -> R2 regression * walrus operator -> silently skipped, no crash * method on undeclared self attr -> no phantom edge
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
Why
The embed/ module's backend-facade pattern (
self._backend: _Json | _Lance) was producing 17 false-positive dead-code findings. R2 only handled single-type class annotations.Effect on self-graph
Dead code: 24 → 14 (-10). All backend methods now resolved correctly. The remaining 5 EmbeddingStore facade methods need local-variable type inference (R4+).
Tests
Schema
Node.metadata.attr_types migrated dict[str, str] → dict[str, list[str]] with back-compat tolerance for the old shape.