From d42085822b28bfef83bcdef60cd0d2fb8e9d064e Mon Sep 17 00:00:00 2001 From: Jake Faulkner Date: Tue, 8 Sep 2026 23:12:40 +1200 Subject: [PATCH 1/2] Align moment magnitude overload defaults with the implementations The overload stubs for moment_to_magnitude and magnitude_to_moment put the default on the Literal[False] variant, while both implementations default bold_m to True. A bare moment_to_magnitude(m) was therefore typed Mw but computed a BoldM -- a real 0.033 magnitude unit (~5% moment) discrepancy between the declared and actual convention. Moves the default onto the Literal[True] overloads. Verified with ty: moment_to_magnitude(1e19) now reveals BoldM rather than Mw, and magnitude_to_moment(BoldM(6.6)) no longer reports "Expected Mw, found BoldM". Fixes #90 Co-Authored-By: Claude Opus 5 --- source_modelling/moment.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source_modelling/moment.py b/source_modelling/moment.py index a4a7c16b..b9c3b26a 100644 --- a/source_modelling/moment.py +++ b/source_modelling/moment.py @@ -134,11 +134,11 @@ def moment_rate_over_time_from_slip( @typing.overload def moment_to_magnitude( - moment: float, bold_m: typing.Literal[True] + moment: float, bold_m: typing.Literal[True] = True ) -> BoldM: ... # numpydoc ignore=GL08 @typing.overload def moment_to_magnitude( - moment: float, bold_m: typing.Literal[False] = False + moment: float, bold_m: typing.Literal[False] ) -> Mw: ... # numpydoc ignore=GL08 def moment_to_magnitude(moment: float, bold_m: bool = True) -> BoldM | Mw: """Convert moment to magnitude. @@ -189,11 +189,11 @@ def moment_to_magnitude(moment: float, bold_m: bool = True) -> BoldM | Mw: @typing.overload def magnitude_to_moment( - magnitude: BoldM, bold_m: typing.Literal[True] + magnitude: BoldM, bold_m: typing.Literal[True] = True ) -> float: ... # numpydoc ignore=GL08 @typing.overload def magnitude_to_moment( - magnitude: Mw, bold_m: typing.Literal[False] = False + magnitude: Mw, bold_m: typing.Literal[False] ) -> float: ... # numpydoc ignore=GL08 def magnitude_to_moment(magnitude: BoldM | Mw, bold_m: bool = True) -> float: """Convert magnitude to moment. From 06856cbeda03f1cdd267b7aa4b765eaa2bf6a54c Mon Sep 17 00:00:00 2001 From: Jake Faulkner Date: Tue, 8 Sep 2026 23:24:33 +1200 Subject: [PATCH 2/2] Pass bold_m=False where an Mw is given to magnitude_to_moment Corrected overload defaults surfaced a genuine inconsistency in test_moment.py: the call constructs an Mw(5.0) but omitted bold_m, so at runtime bold_m defaulted to True and the BoldM formula was applied to an Mw value. The test only asserts that a later KeyError is raised, so the wrong magnitude went unnoticed. Co-Authored-By: Claude Opus 5 --- tests/test_moment.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_moment.py b/tests/test_moment.py index aa1ded76..a5f4b06c 100644 --- a/tests/test_moment.py +++ b/tests/test_moment.py @@ -199,7 +199,7 @@ def test_point_source_slip_bad_dataframe(): } ) - moment_newton_metre = moment.magnitude_to_moment(Mw(5.0)) + moment_newton_metre = moment.magnitude_to_moment(Mw(5.0), bold_m=False) # Should raise KeyError when trying to access missing columns with pytest.raises(KeyError):