TypedDict: Recognize declaration of TypedDict('Point', {'x': int, 'y': int}). (#2206)
This is really just the first phase, doing the syntactic analysis; type checking will follow as a separate PR, as will improvements like keyword args.
diff --git a/mypy_extensions.py b/mypy_extensions.py
index 459d691..db66f58 100644
--- a/mypy_extensions.py
+++ b/mypy_extensions.py
@@ -7,4 +7,16 @@
# NOTE: This module must support Python 2.7 in addition to Python 3.x
-# (TODO: Declare TypedDict and other extensions here)
+
+def TypedDict(typename, fields):
+ """TypedDict creates a dictionary type that expects all of its
+ instances to have a certain set of keys, with each key
+ associated with a value of a consistent type. This expectation
+ is not checked at runtime but is only enforced by typecheckers.
+ """
+ def new_dict(*args, **kwargs):
+ return dict(*args, **kwargs)
+
+ new_dict.__name__ = typename
+ new_dict.__supertype__ = dict
+ return new_dict