-
-
Notifications
You must be signed in to change notification settings - Fork 384
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
Add hash eq and neq operations to TShape #1375
Add hash eq and neq operations to TShape #1375
Conversation
Reviewer's Guide by SourceryThis pull request implements hash, equality, and inequality operations for the TShape class in the TopoDS module. It addresses an issue where these operations were not properly implemented, leading to unexpected behavior when comparing TShape objects or using them in sets/dictionaries. Class diagram for updated TopoDS_TShape operationsclassDiagram
class TopoDS_TShape {
+__hash__() size_t
+__eq__(self, right) bool
+__ne__(self, right) bool
}
note for TopoDS_TShape "Added hash, eq, and neq operations"
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Hey @JohannesVerherstraeten - I've reviewed your changes and they look great!
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
def __ne__(self, right): | ||
try: | ||
return self.__ne_wrapper__(right) | ||
except: | ||
return True |
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.
suggestion (bug_risk): Consider using more specific exception handling in ne and eq methods.
The current implementation catches all exceptions and returns a default value. This might hide unexpected errors. Consider catching specific exceptions that you expect might occur during the comparison.
def __ne__(self, right): | |
try: | |
return self.__ne_wrapper__(right) | |
except: | |
return True | |
def __ne__(self, right): | |
try: | |
return self.__ne_wrapper__(right) | |
except (TypeError, AttributeError): | |
return True |
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 copied these method implementations from TopoDS_Shape, but it's true that the try-except is a bit weird.
Unless there is a specific reason to do it this way, I would remove the try-except from both the Shape and TShape implementations.
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.
Thank you for your feedback, we will generate fewer comments like this in the future according to the following instructions:
- Avoid suggesting changes that are not directly related to the functionality or correctness of the code.
- Ensure that suggestions are necessary and improve the code's robustness or readability.
- Do not include suggestions that might introduce unnecessary complexity or are based on personal preference unless they address a clear issue.
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.
Without the try except statement, something like:
a_topods_shape != "Hi!"
would segfault because the right member is not a TopoDS_Shape. Using ``ìsinstance``` would certainly be better
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.
Ah yes I see. I'll make a new commit using isinstance
Thank you @JohannesVerherstraeten for this contribution. It is strange the neq_ or eq operators are not handled by default for the TopoDS_TShape class, all c++ classes that implement the != operator should benefit from this addition. |
size_t __hash__() { | ||
return opencascade::hash(self);} | ||
}; | ||
|
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.
The TopoDS_Shape
inherits from Standard_Transient
, I think the __hash__
method could be moved to the base class, and would also benefit to all other classes derived from Standard_Transient
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.
Good point, I'll move the __hash__
to Standard_Transient
together with the __eq__
and __neq__
methods.
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.
no need to, I did it there's a build going on
superseded by #1382 |
Thanks tpaviot, I'll close this PR |
thank you @JohannesVerherstraeten feel free to contribute swig stuff whenever you want, I'll review changes as fast as I can |
Fixes the issue where the
__hash__
,__eq__
and__neq__
operators of TopoDS_TShape are not implemented, giving unexpected results like:This fix allows properly comparing TopoDS_TShapes and using them in sets/dictionaries.
Summary by Sourcery
Implement hash, equality, and inequality operators for TopoDS_TShape to fix comparison issues and enable usage in sets and dictionaries, and add corresponding tests.
New Features:
__hash__
,__eq__
, and__neq__
operators for TopoDS_TShape to enable proper comparison and usage in sets and dictionaries.Tests:
__hash__
,__eq__
, and__neq__
operators of TopoDS_TShape to ensure correct functionality.