-
Notifications
You must be signed in to change notification settings - Fork 1.1k
PYTHON-5172 bugfix: Add __repr__ and __eq__ to bson.binary.BinaryVector #2162
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
Changes from 2 commits
519291c
a4ce5c7
8b46ecf
ba43d0c
b83bee4
8bd9482
389b1cf
916ec33
023d8ca
ceb6786
f35ef2b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -247,6 +247,9 @@ def __init__(self, data: Sequence[float | int], dtype: BinaryVectorDtype, paddin | |
self.dtype = dtype | ||
self.padding = padding | ||
|
||
def __repr__(self) -> str: | ||
return f"BinaryVector - {self.dtype=}, {self.dtype},{self.padding=}, {self.data=}" | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hold up, the real bug here is that we're using There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe that we had issues with the combo of {dataclass, slots, defaults}. So I've just removed the dataclass decorator. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are there any other features that will break by removing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think so. As mentioned in the closed PR, we've done init, and repr, and we don't want to rely on equality except via the binary representation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code seems happy to be a dataclass or not. I have no strong preference. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you show an example of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure. It's easy to try. Put a breakpoint on line 83 of test_bson_binary.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
>>> from bson.binary import *
>>> BinaryVector([1], BinaryVectorDtype.INT8) == BinaryVector([2], BinaryVectorDtype.INT8)
True So we need to remove dataclass and implement There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. Take a look. I hate subtleties with == and floats.. |
||
|
||
class Binary(bytes): | ||
"""Representation of BSON binary data. | ||
|
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 needs to follow Python's convention for repr: https://docs.python.org/3/library/functions.html#repr
And we should add tests for this like we do for our other custom type reprs.