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

Add hash/eq/neq for Standard_Transient and its derivatives #1382

Merged
merged 2 commits into from
Nov 8, 2024

Conversation

tpaviot
Copy link
Owner

@tpaviot tpaviot commented Nov 8, 2024

and a couple other minor fixes

based on #1375

Summary by Sourcery

Add hash, equality, and inequality operators for Standard_Transient and its derivatives, enhancing object comparison capabilities. Refactor existing operator implementations for improved readability. Include new tests to verify the functionality of these operators.

New Features:

  • Introduce hash, equality, and inequality operators for Standard_Transient and its derivatives.

Enhancements:

  • Refactor equality and inequality operator implementations for better readability across multiple classes.

Tests:

  • Add tests for hash, equality, and inequality operators for TShape objects.

Copy link

sourcery-ai bot commented Nov 8, 2024

Reviewer's Guide by Sourcery

This PR implements hash, equality, and inequality operators for Standard_Transient and its derivatives, along with code formatting improvements. The changes primarily focus on adding Python special methods (eq, ne, hash) to enable proper comparison and hashing of objects, while also cleaning up code indentation across multiple files.

Class diagram for Standard_Transient and its derivatives

classDiagram
    class Standard_Transient {
        +__eq__(right)
        +__ne__(right)
        +__hash__()
        +__eq_wrapper__(other)
        +__ne_wrapper__(other)
    }
    class Standard_GUID {
        +friend struct std::hash
    }
    class TDF_Label {
        +friend struct std::hash
    }
    class XCAFPrs_Style {
        +friend struct std::hash
    }
    note for Standard_Transient "Added Python special methods for comparison and hashing"
Loading

File-Level Changes

Change Details Files
Added hash, equality, and inequality operators for Standard_Transient
  • Implemented eq method with type checking
  • Implemented ne method with type checking
  • Added hash method using opencascade::hash
  • Added new tests for TShape hash, equality, and inequality operators
src/SWIG_files/wrapper/Standard.i
test/test_core_wrapper_features.py
Improved code formatting and indentation across multiple wrapper files
  • Fixed indentation in equality and inequality operator implementations
  • Standardized spacing around operators
  • Cleaned up friend declarations
src/SWIG_files/wrapper/Graphic3d.i
src/SWIG_files/wrapper/TCollection.i
src/SWIG_files/wrapper/Quantity.i
src/SWIG_files/wrapper/BRepMesh.i
src/SWIG_files/wrapper/TopoDS.i
src/SWIG_files/wrapper/TDF.i
src/SWIG_files/wrapper/XCAFPrs.i
src/SWIG_files/wrapper/TopLoc.i
Removed Open method from RWPly_PlyWriterContext
  • Removed Open method implementation
  • Added methodnotwrapped decorator for Open method
src/SWIG_files/wrapper/RWPly.i

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @tpaviot - I've reviewed your changes and they look great!

Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

# Create a shape that differs from shape_2, but has the same TShape
shape_3 = shape_2.Reversed()
assert hash(shape_1.TShape()) == hash(shape_1.TShape())
assert not hash(shape_1.TShape()) == hash(shape_2.TShape())
Copy link

Choose a reason for hiding this comment

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

suggestion (code-quality): Simplify logical expression using De Morgan identities (de-morgan)

Suggested change
assert not hash(shape_1.TShape()) == hash(shape_2.TShape())
assert hash(shape_1.TShape()) != hash(shape_2.TShape())

Comment on lines +558 to +560
assert not shape_1.TShape() == shape_2.TShape()
assert shape_2.TShape() == shape_3.TShape()
assert not shape_1.TShape() == "some_string"
Copy link

Choose a reason for hiding this comment

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

issue (code-quality): Simplify logical expression using De Morgan identities [×2] (de-morgan)

Comment on lines +568 to +570
assert not shape_1.TShape() != shape_1.TShape()
assert shape_1.TShape() != shape_2.TShape()
assert not shape_2.TShape() != shape_3.TShape()
Copy link

Choose a reason for hiding this comment

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

issue (code-quality): Simplify logical expression using De Morgan identities [×2] (de-morgan)

@tpaviot
Copy link
Owner Author

tpaviot commented Nov 8, 2024

see the related commit at pythonocc-generator tpaviot/pythonocc-generator@e8e3cbf

@tpaviot tpaviot merged commit d02161a into master Nov 8, 2024
15 checks passed
@tpaviot tpaviot deleted the review/hash-eq-neq-Standard_Tranient branch November 8, 2024 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant