Skip to content

gh-148259: make list.remove atomic for non-trivial __eq__ comparison#148440

Open
KowalskiThomas wants to merge 3 commits intopython:mainfrom
KowalskiThomas:kowalski/bug-prevent-race-condition-in-list-remove
Open

gh-148259: make list.remove atomic for non-trivial __eq__ comparison#148440
KowalskiThomas wants to merge 3 commits intopython:mainfrom
KowalskiThomas:kowalski/bug-prevent-race-condition-in-list-remove

Conversation

@KowalskiThomas
Copy link
Copy Markdown
Contributor

@KowalskiThomas KowalskiThomas commented Apr 12, 2026

What is this PR?

This PR addresses the bug reported in #148259 where calling rich comparison may result in releasing the GIL which may result in list.remove removing the wrong item from the list.

The PR also updates the tests added for #126033.

Copy link
Copy Markdown
Contributor

@colesbury colesbury left a comment

Choose a reason for hiding this comment

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

@KowalskiThomas KowalskiThomas force-pushed the kowalski/bug-prevent-race-condition-in-list-remove branch from 858e505 to c30ea14 Compare April 13, 2026 21:21
Copy link
Copy Markdown
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

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

The raises parameter is now misleading. Please correct it. In addition, please add tests to list itself. And please also update the docs if they need to.

Overall, I'm not convinced by this change. Mutating the list while doing the comparison is unsafe. We just don't want to crash. But making it raise a RuntimeError does not necessarily makes it better. Otherwise, we need to do it for all other mutable sequences in C to have more or less the same behavior.

cc @rhettinger

@bedevere-app
Copy link
Copy Markdown

bedevere-app bot commented Apr 13, 2026

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants