Skip to content

Commit a8b3ddb

Browse files
authored
Merge pull request #2513 from plotly/fix/#2512
Raise error when iterating over patch objects.
2 parents 55753d7 + 723ecb5 commit a8b3ddb

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This project adheres to [Semantic Versioning](https://semver.org/).
99
- [#2508](https://github.com/plotly/dash/pull/2508) Fix error message, when callback output has different length than spec
1010
- [#2207](https://github.com/plotly/dash/pull/2207) Fix object of components support.
1111
- [#2500](https://github.com/plotly/dash/pull/2500) Passing customdata by click for scattermapbox, fix [#2493](https://github.com/plotly/dash/issues/2493)
12+
- [#2513](https://github.com/plotly/dash/pull/2513) Raise error when iterating over patch objects, fix [#2512](https://github.com/plotly/dash/issues/2512)
1213

1314
## Updated
1415

Diff for: dash/_patch.py

+6
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ def __ior__(self, other):
9999
self.update(E=other)
100100
return _noop
101101

102+
def __iter__(self):
103+
raise TypeError("Patch objects are write-only, you cannot iterate them.")
104+
105+
def __repr__(self):
106+
return f"<write-only dash.Patch object at {self._location}>"
107+
102108
def append(self, item):
103109
"""Add the item to the end of a list"""
104110
self._operations.append(_operation("Append", self._location, value=item))

Diff for: tests/unit/test_patch.py

+8
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,11 @@ def test_pat020_patch_pickle():
255255
q = pickle.loads(data)
256256

257257
assert patch_to_dict(p) == patch_to_dict(q)
258+
259+
260+
def test_pat021_patch_iter():
261+
p = Patch()
262+
263+
with pytest.raises(TypeError):
264+
for _ in p["invalid"]:
265+
print("invalid iteration")

0 commit comments

Comments
 (0)