Skip to content

Commit 560f2ec

Browse files
rowilliagvanrossum
authored andcommitted
Allow isinstance checks of TypedDict from the typing module (#2615)
Fixes #2614
1 parent 365bdc5 commit 560f2ec

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

extensions/mypy_extensions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
def _check_fails(cls, other):
1717
try:
18-
if sys._getframe(1).f_globals['__name__'] not in ['abc', 'functools']:
18+
if sys._getframe(1).f_globals['__name__'] not in ['abc', 'functools', 'typing']:
1919
# Typed dicts are only for static structural subtyping.
2020
raise TypeError('TypedDict does not support instance and class checks')
2121
except (AttributeError, ValueError):

mypy/test/testextensions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,12 @@ def test_pickle(self):
114114
EmpDnew = pickle.loads(ZZ)
115115
self.assertEqual(EmpDnew({'name': 'jane', 'id': 37}), jane)
116116

117+
def test_optional(self):
118+
EmpD = TypedDict('EmpD', name=str, id=int)
119+
120+
self.assertEqual(typing.Optional[EmpD], typing.Union[None, EmpD])
121+
self.assertNotEqual(typing.List[EmpD], typing.Tuple[EmpD])
122+
117123

118124
if __name__ == '__main__':
119125
main()

0 commit comments

Comments
 (0)