tpaviot / pythonocc-core

Python package for 3D geometry CAD/BIM/CAM
GNU Lesser General Public License v3.0
1.39k stars 379 forks source link

Update DataExchange.py read_step #1373

Closed rsm-gh closed 1 month ago

rsm-gh commented 1 month ago

When using as_compound=True, the method was returning a shape instead of a compound, if there was only 1 shape to convert.

Summary by Sourcery

Correct the return behavior of the read_step_file function to ensure it returns a list of shapes when as_compound is True, even if there is only one shape.

Bug Fixes:

sourcery-ai[bot] commented 1 month ago

Reviewer's Guide by Sourcery

This pull request updates the read_step_file function in DataExchange.py to consistently return a list of shapes when as_compound=True, regardless of the number of shapes found in the STEP file. The change ensures that the function's behavior is more consistent and predictable.

Updated class diagram for DataExchange.py

classDiagram
    class DataExchange {
        +read_step_file(filename, as_compound=True, verbosity=True)
    }
    class step_reader {
        +Shape(int)
        +IsNull()
    }
    class list_of_shapes_to_compound {
        +list_of_shapes_to_compound(shapes)
    }
    DataExchange --> step_reader : uses
    DataExchange --> list_of_shapes_to_compound : uses

File-Level Changes

Change Details Files
Modify the handling of single shape case to return a list
  • Replace direct return of single shape with creation of a list containing that shape
  • Adjust the conditional structure to handle both single and multiple shape cases similarly
  • Move the compound creation and list return logic outside of the shape count conditions
src/Extend/DataExchange.py
Simplify the control flow of the function
  • Remove redundant conditional checks
  • Eliminate unreachable code
  • Consolidate the compound creation and return logic
src/Extend/DataExchange.py

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](https://app.sourcery.ai) 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 - [Contact our support team](mailto:support@sourcery.ai) for questions or feedback. - Visit our [documentation](https://docs.sourcery.ai) for detailed guides and information. - Keep in touch with the Sourcery team by following us on [X/Twitter](https://x.com/SourceryAI), [LinkedIn](https://www.linkedin.com/company/sourcery-ai/) or [GitHub](https://github.com/sourcery-ai).
rsm-gh commented 1 month ago

I included this commit because it makes more sens to always respect the same type of object, but actually when there is only 1 shape, I do not see much difference between the compound and the shape, so I guess that's why you removed it from newer versions (at 7.5 the code seems OK)