diff --git a/dash/_patch.py b/dash/_patch.py index 35af8e0730..fe5f618170 100644 --- a/dash/_patch.py +++ b/dash/_patch.py @@ -99,6 +99,9 @@ def __ior__(self, other): self.update(E=other) return _noop + def __iter__(self): + raise TypeError("Iterating over patch objects is prohibited.") + def append(self, item): """Add the item to the end of a list""" self._operations.append(_operation("Append", self._location, value=item)) diff --git a/tests/unit/test_patch.py b/tests/unit/test_patch.py index 03b7cc1843..c3298f64bf 100644 --- a/tests/unit/test_patch.py +++ b/tests/unit/test_patch.py @@ -255,3 +255,11 @@ def test_pat020_patch_pickle(): q = pickle.loads(data) assert patch_to_dict(p) == patch_to_dict(q) + + +def test_pat021_patch_iter(): + p = Patch() + + with pytest.raises(TypeError): + for _ in p["invalid"]: + print("invalid iteration")