Repository navigation
fix(analyzer): support member access on Annotated alias values - #11691
Henry Su (hsusul) wants to merge 3 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. |
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.
f7c9b2f to
348b77a
Compare
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.