Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7d805b3

Browse files
ilevkivskyihauntsaninja
authored andcommitted
Unwrap TypedDict item types before storing (#17640)
Fixes#17604Fixes#17608Fix is trivial, rectify an obvious omission in my original PR.(cherry picked from commitb56f357)
1 parent32675dd commit7d805b3

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

‎mypy/semanal_typeddict.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,9 @@ def analyze_typeddict_classdef_fields(
323323
returnNone, [], [],set()# Need to defer
324324
types.append(analyzed)
325325
ifnothas_placeholder(analyzed):
326-
stmt.type=analyzed
326+
stmt.type= (
327+
analyzed.itemifisinstance(analyzed,RequiredType)elseanalyzed
328+
)
327329
# ...despite possible minor failures that allow further analysis.
328330
ifstmt.typeisNoneorhasattr(stmt,"new_syntax")andnotstmt.new_syntax:
329331
self.fail(TPDICT_CLASS_ERROR,stmt)

‎test-data/unit/check-typeddict.test‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2382,6 +2382,14 @@ class ForceDeferredEval: pass
23822382
[builtins fixtures/dict.pyi]
23832383
[typing fixtures/typing-typeddict.pyi]
23842384

2385+
[case testTypedDictRequiredUnimportedAny]
2386+
# flags: --disallow-any-unimported
2387+
from typing import NotRequired, TypedDict
2388+
from nonexistent import Foo # type: ignore[import-not-found]
2389+
class Bar(TypedDict):
2390+
foo: NotRequired[Foo] # E: Type of variable becomes "Any" due to an unfollowed import
2391+
[typing fixtures/typing-typeddict.pyi]
2392+
23852393
-- Required[]
23862394

23872395
[case testDoesRecognizeRequiredInTypedDictWithClass]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp