From 6f8480c9d1dcbcacc8bc248665cfbb42c9920270 Mon Sep 17 00:00:00 2001 From: Marco Gorelli <33491632+MarcoGorelli@users.noreply.github.com> Date: Wed, 9 Oct 2019 19:38:37 +0100 Subject: [PATCH] Update examples of mutable and non-mutable mapping in cheat sheet (#7620) --- docs/source/cheat_sheet_py3.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/source/cheat_sheet_py3.rst b/docs/source/cheat_sheet_py3.rst index 22e2dc10fb97..47b36e24d351 100644 --- a/docs/source/cheat_sheet_py3.rst +++ b/docs/source/cheat_sheet_py3.rst @@ -212,12 +212,13 @@ that are common in idiomatic Python are standardized. # Mapping describes a dict-like object (with "__getitem__") that we won't # mutate, and MutableMapping one (with "__setitem__") that we might def f(my_dict: Mapping[int, str]) -> List[int]: + my_mapping[5] = 'maybe' # if we try this, mypy will throw an error... return list(my_dict.keys()) f({3: 'yes', 4: 'no'}) def f(my_mapping: MutableMapping[int, str]) -> Set[str]: - my_mapping[5] = 'maybe' + my_mapping[5] = 'maybe' # ...but mypy is OK with this. return set(my_mapping.values()) f({3: 'yes', 4: 'no'})