summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorZac Hatfield-Dodds <Zac-HD@users.noreply.github.com>2019-11-24 10:48:48 (GMT)
committerIvan Levkivskyi <levkivskyi@gmail.com>2019-11-24 10:48:48 (GMT)
commit665ad3dfa9993b9a4000b097ddead4e292590e8c (patch)
tree886741ee4ffc36e769575e51b5e576d1f8e22b02 /Lib/test
parent041d8b48a2e59fa642b2c5124d78086baf74e339 (diff)
downloadcpython-665ad3dfa9993b9a4000b097ddead4e292590e8c.zip
cpython-665ad3dfa9993b9a4000b097ddead4e292590e8c.tar.gz
cpython-665ad3dfa9993b9a4000b097ddead4e292590e8c.tar.bz2
Better runtime TypedDict (GH-17214)
This patch enables downstream projects inspecting a TypedDict subclass at runtime to tell which keys are optional. This is essential for generating test data with Hypothesis or validating inputs with typeguard or pydantic.
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_typing.py7
1 files changed, 7 insertions, 0 deletions
diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index ccd617c..5b4916f 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -3741,6 +3741,13 @@ class TypedDictTests(BaseTestCase):
self.assertEqual(Options(log_level=2), {'log_level': 2})
self.assertEqual(Options.__total__, False)
+ def test_optional_keys(self):
+ class Point2Dor3D(Point2D, total=False):
+ z: int
+
+ assert Point2Dor3D.__required_keys__ == frozenset(['x', 'y'])
+ assert Point2Dor3D.__optional_keys__ == frozenset(['z'])
+
class IOTests(BaseTestCase):