From 3b0f3f2a351227e3d1b81a8b39dad806628cde3c Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Fri, 28 Apr 2017 14:07:29 +0100 Subject: [PATCH 1/2] Add failing test case --- test-data/unit/check-incremental.test | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test-data/unit/check-incremental.test b/test-data/unit/check-incremental.test index 7d3d6d862fe62..b6f92bd6a174e 100644 --- a/test-data/unit/check-incremental.test +++ b/test-data/unit/check-incremental.test @@ -1907,6 +1907,23 @@ a.A().x = 0 [out2] tmp/b.py:2: error: Cannot assign to class variable "x" via instance +[case testSerializeTypedDict] +import b +reveal_type(b.x) +y: b.A +reveal_type(y) +[file b.py] +from mypy_extensions import TypedDict +A = TypedDict('A', {'x': int, 'y': str}) +x: A +[builtins fixtures/dict.pyi] +[out1] +main:2: error: Revealed type is 'TypedDict(x=builtins.int, y=builtins.str, _fallback=b.A)' +main:4: error: Revealed type is 'TypedDict(x=builtins.int, y=builtins.str, _fallback=b.A)' +[out2] +main:2: error: Revealed type is 'TypedDict(x=builtins.int, y=builtins.str, _fallback=b.A)' +main:4: error: Revealed type is 'TypedDict(x=builtins.int, y=builtins.str, _fallback=b.A)' + [case testQuickAndDirty1] # flags: --quick-and-dirty import b, c From 0c6461775b15f42782a3dee2da6eee2aa806a3a7 Mon Sep 17 00:00:00 2001 From: Jukka Lehtosalo Date: Fri, 28 Apr 2017 14:07:44 +0100 Subject: [PATCH 2/2] Fix crash due to deserialization of TypedDict type objects A TypeInfo attribute was not handled during fixup, causing a crash when using a TypedDict type imported from a deserialized module in an annotation. Fixes #3272. --- mypy/fixup.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mypy/fixup.py b/mypy/fixup.py index 0d85feb86ef5a..247fb4997ccb2 100644 --- a/mypy/fixup.py +++ b/mypy/fixup.py @@ -64,6 +64,8 @@ def visit_type_info(self, info: TypeInfo) -> None: info._promote.accept(self.type_fixer) if info.tuple_type: info.tuple_type.accept(self.type_fixer) + if info.typeddict_type: + info.typeddict_type.accept(self.type_fixer) finally: self.current_info = save_info