Fix invalid-literal error when using Annotated Literal in a type alias#2634
Fix invalid-literal error when using Annotated Literal in a type alias#2634fangyi-zhou wants to merge 5 commits intofacebook:mainfrom
Conversation
This comment has been minimized.
This comment has been minimized.
Primer Diff Classification❌ 1 regression(s) | 1 project(s) total 1 regression(s) across prefect. error kinds:
Detailed analysis❌ Regression (1)prefect (+24, -1)
Was this helpful? React with 👍 or 👎 Classification by primer-classifier (1 LLM) |
|
Diff from mypy_primer, showing the effect of this PR on open source code: cloud-init (https://github.com/canonical/cloud-init)
- ERROR cloudinit/distros/ug_util.py:40:25-59: Object of class `NoneType` has no attribute `extend` [missing-attribute]
+ ERROR cloudinit/distros/ug_util.py:40:45-52: No matching overload found for function `typing.MutableMapping.setdefault` called with arguments: (Unknown, list[@_]) [no-matching-overload]
prefect (https://github.com/PrefectHQ/prefect)
- ERROR src/prefect/blocks/core.py:1046:16-51: Returned type `tuple[BlockDocument, Name | None]` is not assignable to declared return type `tuple[BlockDocument, str]` [bad-return]
+ ERROR src/prefect/blocks/core.py:1046:16-51: Returned type `tuple[BlockDocument, str | None]` is not assignable to declared return type `tuple[BlockDocument, str]` [bad-return]
|
Primer Diff Classification❌ 1 regression(s) | ➖ 1 neutral | 2 project(s) total 1 regression(s) across cloud-init. error kinds:
Detailed analysis❌ Regression (1)cloud-init (+1, -1)
➖ Neutral (1)prefect (+1, -1)
Suggested FixSummary: The PR's changes to handle Annotated types in type alias resolution have disrupted type inference for dictionary operations, causing 1. In the type alias resolution logic in solve.rs around line 1505, add a guard to ensure that when unwrapping Annotated types, the inference context is preserved. The issue is that
2. In is_valid_literal() in specials.rs, modify the Annotated case to preserve type inference context. Instead of just
Was this helpful? React with 👍 or 👎 Classification by primer-classifier (1 heuristic, 1 LLM) |
stroxler
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
yangdanny97
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
Summary
Fixes #2633, a regression introduced by #2572, where we model
Annotatedin a separate constructor.There are two issues here:
Annotatedtypes are not resolved (thus being anUntypedAlias): this is becauseAnnotatedis now its own type, which is not always aTypefor triggering the type alias resolution. The fix is to handleAnnotatedtype in the resolution processing, and removing theAnnotatedwrapper.Annotatedtypes are not handled inLiteralcheck: this is a straightforward fix to check the inner type when encountering anAnnotatedtype.Test Plan
Added a regression test.