Skip to content

Commit

Permalink
Raise error when iterating over patch objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
T4rk1n committed Apr 24, 2023
1 parent 69b3d5d commit c0246a2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions dash/_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
8 changes: 8 additions & 0 deletions tests/unit/test_patch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit c0246a2

Please # to comment.