Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion mypy/semanal_typeddict.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,14 @@ def parse_typeddict_fields_with_types(
type = expr_to_unanalyzed_type(field_type_expr, self.options,
self.api.is_stub_file)
except TypeTranslationError:
self.fail_typeddict_arg('Invalid field type', field_type_expr)
if (isinstance(field_type_expr, CallExpr) and
isinstance(field_type_expr.callee, RefExpr) and
field_type_expr.callee.fullname in TPDICT_NAMES):
self.fail_typeddict_arg(
'Inline TypedDict types not supported; use assignment to define TypedDict',
field_type_expr)
else:
self.fail_typeddict_arg('Invalid field type', field_type_expr)
return [], [], False
analyzed = self.api.anal_type(type)
if analyzed is None:
Expand Down
8 changes: 8 additions & 0 deletions test-data/unit/check-typeddict.test
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ Point = TypedDict('Point', {'x': int, 'y': int})
p = Point(x='meaning_of_life', y=1337) # E: Incompatible types (expression has type "str", TypedDict item "x" has type "int")
[builtins fixtures/dict.pyi]

[case testCannotCreateTypedDictInstanceWithInlineTypedDict]
from mypy_extensions import TypedDict
D = TypedDict('D', {
'x': TypedDict('E', { # E: Inline TypedDict types not supported; use assignment to define TypedDict
'y': int
})
})
[builtins fixtures/dict.pyi]

-- Define TypedDict (Class syntax)

Expand Down