Skip to content

Commit 9bb31f4

Browse files
davidfstrgvanrossum
authored andcommitted
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.
1 parent dc725ba commit 9bb31f4

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

mypy_extensions.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,16 @@
77

88
# NOTE: This module must support Python 2.7 in addition to Python 3.x
99

10-
# (TODO: Declare TypedDict and other extensions here)
10+
11+
def TypedDict(typename, fields):
12+
"""TypedDict creates a dictionary type that expects all of its
13+
instances to have a certain set of keys, with each key
14+
associated with a value of a consistent type. This expectation
15+
is not checked at runtime but is only enforced by typecheckers.
16+
"""
17+
def new_dict(*args, **kwargs):
18+
return dict(*args, **kwargs)
19+
20+
new_dict.__name__ = typename
21+
new_dict.__supertype__ = dict
22+
return new_dict

0 commit comments

Comments
 (0)