Skip to content

Apply match-case instead of if-elif - #4599

Merged
clmould merged 37 commits into
mainfrom
apply_match_case
Sep 29, 2026
Merged

clmould merged 37 commits into
mainfrom
apply_match_case

Conversation

@chris-ashe

Copy link
Copy Markdown
Member

Description

Since we now require Python >=3.10 we should use match-case statements over if-else because it supports structural pattern matching, avoids repeating the same variable name, and makes complex conditional checks much easier to read

Checklist

I confirm that I have completed the following checks:

  • My changes follow the PROCESS style guide
  • I have justified any large differences in the regression tests caused by this pull request in the comments.
  • I have added new tests where appropriate for the changes I have made.
  • If I have had to change any existing unit or integration tests, I have justified this change in the pull request comments.
  • If I have made documentation changes, I have checked they render correctly.
  • I have added documentation for my change, if appropriate.

@codecov-commenter

codecov-commenter commented Sep 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 33.82594% with 806 lines in your changes missing coverage. Please review.
✅ Project coverage is 49.88%. Comparing base (5d2d7d5) to head (d2491da).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
process/models/tfcoil/superconducting.py 34.48% 114 Missing ⚠️
process/models/tfcoil/base.py 25.00% 105 Missing ⚠️
process/models/physics/plasma_geometry.py 1.23% 80 Missing ⚠️
process/core/io/plot/summary.py 0.00% 79 Missing ⚠️
process/models/physics/confinement_time.py 55.55% 60 Missing ⚠️
process/core/init.py 29.50% 43 Missing ⚠️
process/models/pfcoil.py 53.93% 41 Missing ⚠️
process/core/solver/objectives.py 0.00% 37 Missing ⚠️
process/models/physics/current_drive.py 62.19% 31 Missing ⚠️
process/models/blankets/hcpb.py 33.33% 26 Missing ⚠️
... and 15 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4599      +/-   ##
==========================================
- Coverage   49.99%   49.88%   -0.11%     
==========================================
  Files         151      151              
  Lines       29916    30068     +152     
==========================================
+ Hits        14956    15000      +44     
- Misses      14960    15068     +108     

☔ View full report in Codecov by Harness.
📢 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.

…y in divertor configuration and tokamak aspect ratio logic
@chris-ashe
chris-ashe requested a review from clmould September 16, 2026 09:03
@chris-ashe
chris-ashe marked this pull request as ready for review September 16, 2026 09:04
@chris-ashe
chris-ashe requested a review from a team as a code owner September 16, 2026 09:04
@clmould clmould self-assigned this Sep 16, 2026

@clmould clmould left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Much nicer with match-case than all the if-elses! :)

One more thing - could any return types that have been added be changed to : please ? In the docs it will render with : as long as the return type has been typed in the function definition with -> (https://ukaea.github.io/PROCESS/development/standards/#docstrings)

Comment thread process/core/io/plot/summary.py
Comment thread process/models/build.py Outdated
Comment thread process/models/build.py
Comment thread process/models/vacuum.py Outdated
Comment thread process/models/pfcoil.py
Comment thread process/models/tfcoil/base.py Outdated
Comment thread process/models/tfcoil/base.py Outdated
Comment thread process/models/tfcoil/superconducting.py Outdated
Comment thread process/core/caller.py Outdated
Comment thread process/models/power.py Outdated
Comment thread process/models/vacuum.py Outdated

@clmould clmould left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Also some unresolved comments about adding the _missing_ methods for ConfinementRadiationLossModel, ConfinementTimeModel, PlasmaCurrentModel, PlasmaGeometryModelType to remove the try-excepts, but happy with the rest

Comment thread process/core/io/plot/summary.py Outdated
Comment thread process/core/io/plot/summary.py Outdated
Comment thread process/core/io/plot/summary.py
Comment thread process/core/io/plot/summary.py
Comment thread process/core/init.py Outdated
Comment thread process/models/pfcoil.py
Comment thread process/models/physics/current_drive.py
@clmould
clmould merged commit b8c6786 into main Sep 29, 2026
8 of 11 checks passed
@clmould
clmould deleted the apply_match_case branch September 29, 2026 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants