from .math_clamp import clamp from .money_amount import Money, assert_same_currency, money def clamp_money(amount: Money, min: Money, max: Money) -> Money: # noqa: A002 - the manifest names them min and max """``amount`` held within ``min..max``, all three in one currency. Bounds the wrong way round are an error (from math.clamp), not an answer: capping a refund at the original charge with the bounds swapped is a bug to surface. """ assert_same_currency(amount, min) assert_same_currency(amount, max) return money(clamp(amount.minor, min.minor, max.minor), amount.currency)