Skip to content

Conversation

@SZeltaat
Copy link
Contributor

Description

Hi @egarciamendez. I have already discussed this with Wichard. The approach with Enums had a huge overhead that created all the standard profiles in our library, twice even if we only needed one standard profile. That is due to the nature of Enums. In addition, I was overriding the Enum Meta which is potentially a risk of unknown behaviour. I have tried 2 alternatives, 1: using descriptors (which had the same disadvantage of initiating all profiles eagerly on class definition) and 2: class getattr (this PR).

This approach has a slight disadvantage of creating the stubs, but I can accept that because:

  • We only need to do it once (very rarely we might want to add new standard profiles!)
  • It can be automated (I have written a script that does it automatically for all standard profiles) or done by copliot/AI.

This way we have all the advantages of user-friendly API and clean Pythonic code, without unnecessary overhead at runtime.

Could you please review this PR and let me know what you think?
If approved, I'll make the changes to all the other standard profiles.

Fixes #861

Type of change

  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • New and existing unit tests pass locally with my changes

@codecov
Copy link

codecov bot commented Dec 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (c036530) to head (c86a14d).
⚠️ Report is 3 commits behind head on 734-refactor-steel-profiles.

Additional details and impacted files
@@                      Coverage Diff                      @@
##           734-refactor-steel-profiles      #879   +/-   ##
=============================================================
  Coverage                       100.00%   100.00%           
=============================================================
  Files                              410       410           
  Lines                            12840     12840           
=============================================================
  Hits                             12840     12840           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the standard profiles implementation from an Enum-based approach to a metaclass-based approach to avoid eager initialization overhead. The CHS (Circular Hollow Section) profiles are now accessed through dynamic attribute lookup using StandardProfileMeta, returning CHSProfile instances on demand. Key changes include:

  • Introduction of StandardProfileMeta metaclass for lazy profile instantiation
  • Refactoring of CHS from Enum to a regular class with metaclass
  • Change of API: profile.as_cross_section() replaced with direct profile access and profile.with_corrosion()
  • Addition of .pyi stub file for type hints

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
blueprints/structural_sections/steel/standard_profiles/utils.py Adds StandardProfileMeta metaclass and StandardProfileProtocol for dynamic profile attribute access
blueprints/structural_sections/steel/standard_profiles/chs.py Refactors CHS from Enum to metaclass-based class with database dictionary
blueprints/structural_sections/steel/standard_profiles/chs.pyi New stub file providing type hints for all CHS profile attributes
blueprints/structural_sections/steel/profile_definitions/chs_profile.py Renames from_standard_profile to with_corrosion as an instance method
tests/structural_sections/steel/standard_profiles/test_chs.py Simplifies tests but introduces tautological assertions and reduces coverage
tests/structural_sections/steel/profile_definitions/test_chs_profile.py Updates tests to use new with_corrosion() API
tests/structural_sections/steel/profile_definitions/conftest.py Simplifies fixture to directly return CHS profile instead of converting

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@coderabbitai
Copy link

coderabbitai bot commented Dec 28, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@bro-wi bro-wi left a comment

Choose a reason for hiding this comment

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

Great job! I think we are nearly there. Biggest consideration for me is maintaning two interfaces as now:

CHSProfile() and CHS.CHS21_3x2_3

compared to a single interface:

CHSProfile() and CHSProfile.CHS21_3x2_3

Copy link
Contributor Author

@SZeltaat SZeltaat left a comment

Choose a reason for hiding this comment

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

❤️

@SZeltaat SZeltaat merged commit 42fd536 into 734-refactor-steel-profiles Jan 5, 2026
9 checks passed
@SZeltaat SZeltaat deleted the 861-refactor-standard-profiles-should-subclass-profile branch January 5, 2026 15:40
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.

4 participants