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

Conversation

mattheww
Copy link
Contributor

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.

Copy link
Member

@tshepang tshepang left a comment

Choose a reason for hiding this comment

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

bors merge

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

@bors-ferrocene
Copy link
Contributor

Build succeeded:

  • CI

@bors-ferrocene bors-ferrocene bot merged commit 496ef38 into ferrocene:main Oct 31, 2023
1 check passed
bors-ferrocene bot added a commit to ferrocene/ferrocene that referenced this pull request Oct 31, 2023
75: Automated pull from `ferrocene/specification` r=tshepang a=github-actions[bot]

This PR pulls the following changes from the [`ferrocene/specification`](https://github.com/ferrocene/specification) repository:

* ferrocene/specification#456


Co-authored-by: Matthew Woodcraft <[email protected]>
Co-authored-by: bors-ferrocene[bot] <87868125+bors-ferrocene[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants