Repository navigation
fix(analyzer): support member access on Annotated alias values - #11691
Rich Chiodo (rchiodo) merged 4 commits into
Conversation
|
🔒 Automated review in progress — Bill Schnurr (@bschnurr) is auto-reviewing this PR. |
|
Verification: The relevant tests could not be fully run in the isolated environment; this review is not fully verified. Result: Summary: No tests executed because the verification container could not start: no trusted sandbox image is configured for `microsoft/pyright`. The PR adds the targeted `Annotated10` Jest case covering member access through an `Annotated` alias. Verification is therefore blocked by the environment. Test runs: 2 not run
|
Bill Schnurr (bschnurr)
left a comment
There was a problem hiding this comment.
Approved via Review Center.
Heejae Chang (heejaechang)
left a comment
There was a problem hiding this comment.
Approved via Review Center.
🔴 Pyright CLI QA —
|
|
Not intended. All five QA examples were regressions, fixed in f7c9b2f. The fallback now runs only for reads of non-dunder names on an implicit alias whose
Assignment reports a single error again. |
f7c9b2f to
348b77a
Compare
|
The current head |
At runtime, typing._AnnotatedAlias delegates attribute access to __origin__ (the annotated type). When member access on an Annotated special form fails, fall back to evaluating member access on its underlying typeForm.
Evaluate the fallback against the instantiable form of the annotated class so methods stay unbound, and skip the fallback for non-class origins such as unions, which do not expose their members' attributes at runtime.
…ed alias forwards Limit the fallback to reads of non-dunder names on an implicit alias whose origin is a plain class. Forward references, literals and TypeAliasType origins, PEP 695 aliases, deletion, and values that merely hold an alias are no longer delegated, and assignments no longer report a second error.
348b77a to
ca0228b
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Keep valid class-member reads while rejecting non-class origins, honoring wrapper lookup order, and reporting descriptor errors once. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
In the original QA case, Pyright allowed The follow-up is pushed in fc2a048. It keeps the class-member reads from #11538, but only forwards to established origins, leaves the wrapper’s own attrs alone, and reports a failed descriptor lookup once. AI-assisted comment. |
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
Closes #11538.
Summary of Changes
At runtime,
typing._AnnotatedAlias.__getattr__delegates attribute access to__origin__(the underlying annotated type).In
getTypeOfMemberAccessWithBaseType:baseType.props?.typeFormasbaseTypeFormbefore stripping special forms.Annotatedspecial form produces an error or no member, falls back to evaluating member access against the underlyingtypeForm.annotated10.pyand test suite entry intypeEvaluator7.test.tsverifying member access on anAnnotatedalias value.