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 assertion of pop() result in test_issue_4920 #25209

Merged
merged 1 commit into from Apr 7, 2021

Conversation

steve-s
Copy link
Contributor

@steve-s steve-s commented Apr 6, 2021

Changes the test to not assert concrete result of pop but just that it was an item from the set, and that the set shrunk by one.

The pop method of MutableSet iterates the underlying set object to choose the item to remove. According the the Python language reference "sets do not record element position or order of insertion".

Note: changing the values in the original test to, for example:

        s = MySet([42,43,2,1])
        self.assertEqual(s.pop(), 42)

gives

FAIL: test_issue_4920 (test.test_collections.TestCollectionABCs)
----------------------------------------------------------------------
    self.assertEqual(s.pop(), 42)
AssertionError: 2 != 42

Background: we discovered this issue while developing GraalPython, where a small difference in internal implementation leads to pop() giving a different value in this case.

The pop method of MutableSet iterates the underlying set object to choose
the item to remove. According the the Python language reference "sets do not
record element position or order of insertion".

Changes the test to not assert concrete result of pop, but just that it
was an item from the set, and that the set shrunk by one.
@steve-s steve-s requested a review from rhettinger as a code owner April 6, 2021 07:52
@bedevere-bot bedevere-bot added tests Tests in the Lib/test dir awaiting review labels Apr 6, 2021
@rhettinger rhettinger self-assigned this Apr 7, 2021
@miss-islington
Copy link
Contributor

Thanks @steve-s for the PR, and @rhettinger for merging it 🌮🎉.. I'm working now to backport this PR to: 3.9.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Apr 7, 2021
Changes the test to not assert concrete result of pop, but just that it
was an item from the set, and that the set shrunk by one.
(cherry picked from commit 453074c)

Co-authored-by: Stepan Sindelar <me@stevesindelar.cz>
@bedevere-bot
Copy link

GH-25269 is a backport of this pull request to the 3.9 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.9 only security fixes label Apr 7, 2021
@rhettinger rhettinger added the needs backport to 3.8 only security fixes label Apr 7, 2021
@miss-islington
Copy link
Contributor

Thanks @steve-s for the PR, and @rhettinger for merging it 🌮🎉.. I'm working now to backport this PR to: 3.8.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Apr 7, 2021
Changes the test to not assert concrete result of pop, but just that it
was an item from the set, and that the set shrunk by one.
(cherry picked from commit 453074c)

Co-authored-by: Stepan Sindelar <me@stevesindelar.cz>
@bedevere-bot
Copy link

GH-25270 is a backport of this pull request to the 3.8 branch.

@bedevere-bot bedevere-bot removed the needs backport to 3.8 only security fixes label Apr 7, 2021
kreathon pushed a commit to kreathon/cpython that referenced this pull request May 2, 2021
Changes the test to not assert concrete result of pop, but just that it
was an item from the set, and that the set shrunk by one.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip issue skip news tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants