Align moment magnitude overload defaults with the implementations - #105
Conversation
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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
|
Pushed a follow-up commit: the corrected overload defaults made
moment_newton_metre = moment.magnitude_to_moment(Mw(5.0))The implementation defaults The test only asserts that a later Fixed by passing the convention explicitly:
|
Fixes #90
Problem
The
@typing.overloadstubs put the default on theLiteral[False]variant while both implementations defaultbold_mtoTrue:So a bare
moment_to_magnitude(m)resolved to theLiteral[False]overload and was typedMw, while the value returned at runtime is aBoldM.magnitude_to_momenthad the same mismatch.MwandBoldMare conventions this module deliberately keeps apart in the type system, and the difference is not notional:Verification with
ty(the checker in the dev group)reveal_typeon the three call forms, plus aBoldMpassed positionally:moment_to_magnitude(1e19)Mw❌BoldM✅moment_to_magnitude(1e19, True)BoldMBoldMmoment_to_magnitude(1e19, False)MwMwmagnitude_to_moment(BoldM(6.6))Expected Mw, found BoldMChanges
Runtime behaviour is untouched — this is a stub-only change.
= Trueonto theLiteral[True]overloads.Literal[False]overloads, so passingFalsestays explicit (a default on both variants would make a bare call ambiguous).Verification
pytest tests/test_moment.py— 14 passed.ruff check,ruff format,numpydoc lintclean.🤖 Generated with Claude Code