File tree 1 file changed +38
-0
lines changed
1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -893,6 +893,44 @@ Totality also affects structural compatibility. You can't use a partial
893
893
TypedDict when a total one is expected. Also, a total TypedDict is not
894
894
valid when a partial one is expected.
895
895
896
+ Supported operations
897
+ --------------------
898
+
899
+ TypedDict objects support a subset of dictionary operations and methods.
900
+ You must use string literals as keys when calling most of the methods,
901
+ as otherwise mypy won't be able to check that the key is valid. List
902
+ of supported operations:
903
+
904
+ * Anything included in ``typing.Mapping ``:
905
+
906
+ * ``d[key] ``
907
+ * ``key in d ``
908
+ * ``len(d) ``
909
+ * ``for key in d `` (iteration)
910
+ * ``d.get(key[, default]) ``
911
+ * ``d.keys() ``
912
+ * ``d.values() ``
913
+ * ``d.items() ``
914
+
915
+ * ``d.copy() ``
916
+ * ``d.setdefault(key, default) ``
917
+ * ``d1.update(d2) ``
918
+ * ``d.pop(key[, default]) `` (partial TypedDicts only)
919
+ * ``del d[key] `` (partial TypedDicts only)
920
+
921
+ In Python 2 code, these methods are also supported:
922
+
923
+ * ``has_key(key) ``
924
+ * ``viewitems() ``
925
+ * ``viewkeys() ``
926
+ * ``viervalues() ``
927
+
928
+ .. note ::
929
+
930
+ ``clear() `` and ``popitem() `` are not supported since they are unsafe
931
+ -- they could delete required TypedDict items that are not visible to
932
+ mypy because of structural subtyping.
933
+
896
934
Class-based syntax
897
935
------------------
898
936
You can’t perform that action at this time.
0 commit comments