Skip to content

Commit 496ef38

Browse files
Merge #456
456: Fix RubricCollector.clear_doc() r=tshepang a=mattheww I've seen occasional errors like the following on incremental builds: ```` Extension error (ferrocene_spec.items_with_rubric): Handler <bound method RubricCollector.clear_doc of <ferrocene_spec.items_with_rubric.RubricCollector object at 0x7f4a44a47e50>> for event 'env-purge-doc' threw an exception (exception: pop index out of range) ```` The following code in `exts/ferrocene_spec/items_with_rubric.py` ```` # This makes a copy of the list (with `list(items)`) to be able to # remove items from it without affecting the iteration. for i, item in enumerate(list(items)): if item.document == docname: items.pop(i) ```` won't work as intended if it finds more than one item to remove, because the first `pop` will change the positions of the following elements of the list. Co-authored-by: Matthew Woodcraft <[email protected]>
2 parents 26cdabb + 7d84415 commit 496ef38

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

exts/ferrocene_spec/items_with_rubric.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,7 @@ class RubricCollector(EnvironmentCollector):
4040
def clear_doc(self, app, env, docname):
4141
storage = get_storage(env)
4242
for rubric, items in storage.items():
43-
# This makes a copy of the list (with `list(items)`) to be able to
44-
# remove items from it without affecting the iteration.
45-
for i, item in enumerate(list(items)):
46-
if item.document == docname:
47-
items.pop(i)
43+
items[:] = (item for item in items if item.document != docname)
4844

4945
def merge_other(self, app, env, docnames, other):
5046
current = get_storage(env)

0 commit comments

Comments
 (0)