Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RubricCollector.clear_doc() #456

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions exts/ferrocene_spec/items_with_rubric.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ class RubricCollector(EnvironmentCollector):
def clear_doc(self, app, env, docname):
storage = get_storage(env)
for rubric, items in storage.items():
# 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)
items[:] = (item for item in items if item.document != docname)
Copy link
Member

@tshepang tshepang Oct 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the advantage of doing it this way, instead of...

items = [item for item in items if item.document != docname]

Copy link
Member

@tshepang tshepang Oct 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(answering self) it modifies the list instad of creating a new one

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose the generator is coerced to a list as well (but I don't know the right Python terminology), while the choice of generator is for being gentle to memory, where the items are created only when needed


def merge_other(self, app, env, docnames, other):
current = get_storage(env)
Expand Down