diff --git a/extensions/mypy_extensions.py b/extensions/mypy_extensions.py index 248da3de4aae..efa3c35e8e03 100644 --- a/extensions/mypy_extensions.py +++ b/extensions/mypy_extensions.py @@ -15,7 +15,7 @@ def _check_fails(cls, other): try: - if sys._getframe(1).f_globals['__name__'] not in ['abc', 'functools']: + if sys._getframe(1).f_globals['__name__'] not in ['abc', 'functools', 'typing']: # Typed dicts are only for static structural subtyping. raise TypeError('TypedDict does not support instance and class checks') except (AttributeError, ValueError): diff --git a/mypy/test/testextensions.py b/mypy/test/testextensions.py index eca45d7e54dd..af3916f98e19 100644 --- a/mypy/test/testextensions.py +++ b/mypy/test/testextensions.py @@ -114,6 +114,12 @@ def test_pickle(self): EmpDnew = pickle.loads(ZZ) self.assertEqual(EmpDnew({'name': 'jane', 'id': 37}), jane) + def test_optional(self): + EmpD = TypedDict('EmpD', name=str, id=int) + + self.assertEqual(typing.Optional[EmpD], typing.Union[None, EmpD]) + self.assertNotEqual(typing.List[EmpD], typing.Tuple[EmpD]) + if __name__ == '__main__': main()