-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
gh-140025: fix queue.SimpleQueue.__sizeof__() computation #140086
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
base: main
Are you sure you want to change the base?
Conversation
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
This comment was marked as duplicate.
This comment was marked as duplicate.
…lying data structure
This comment was marked as duplicate.
This comment was marked as duplicate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per the bot, please add a news entry. Please also avoid force-pushing; it makes things harder to review and we squash at the end anyway.
Misc/NEWS.d/next/Library/2025-10-14-14-07-08.gh-issue-140025.zQ_Fhe.rst
Outdated
Show resolved
Hide resolved
Misc/NEWS.d/next/Library/2025-10-14-14-07-08.gh-issue-140025.zQ_Fhe.rst
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall feedback:
- Implement the tests in PySimpleQueueTest and CSimpleQueueTest. They will be different becauss the impmementation is different.
- Remove messages when assertions fail and when the condition being tested is self-explanatory.
- Remove commenta for self-explanatory code.
# C implementation: no change (still within initial ring buffer capacity) | ||
# Python implementation: may change (deque growth, but __sizeof__ may not reflect it) | ||
|
||
# Add one more item to potentially trigger growth |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment is not helpful "potentially" means that the test is non-deterministic.
# For C implementation, this includes the ring buffer array | ||
# For Python implementation, this includes the underlying deque | ||
|
||
# Add items within initial capacity (if applicable) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove such trivial comments. The code is self-explanatory.
# Test that __sizeof__() accounts for underlying data structure | ||
q = self.q | ||
|
||
# Get the size of an empty queue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this comment.
self.assertIsNone(wr()) | ||
|
||
def test_sizeof(self): | ||
# Test that __sizeof__() accounts for underlying data structure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this comment is redundant.
q.put(object()) # Now 9 items | ||
|
||
size_after_9 = q.__sizeof__() | ||
self.assertGreaterEqual(size_after_9, size_after_8, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove messages when assertions fail. They are not useful here
# Size may or may not change depending on implementation | ||
# C implementation: no change (still within initial ring buffer capacity) | ||
# Python implementation: may change (deque growth, but __sizeof__ may not reflect it) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make two tests. One for the C implementation and one for the Pythkn one, each of them in their already existing dedicated class (PySimpleQueueTest and CSimpleQueueTest). That way you can test the exact inequality/equality.
self.assertGreater(large_size, 0, "Python SimpleQueue should have positive size") | ||
|
||
|
||
class PySimpleQueueTest(BaseSimpleQueueTest, unittest.TestCase): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use this class for pure Python-only tests and the class below for the C tests only.
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 |
gh-140025 queue.SimpleQueue.sizeof() ignores the underlying data structure