Consider how to address this in the context of these methods. Since they are underscored (quasi-private) methods, consider returning a tuple of (available_consumed, further_transactions). (Note: this, in combination with using dict.get(key, default), will help make the logic of these methods cleaner, since there's no need to fill out the keys.) Calling methods will need to add the further_transactions to their transactions dict, which might be a bit slower than mutating, but it will be clearer for reading and debugging.
DebtPaymentStrategy._assign_available
andDebtPaymentStrategy._assign_minimums
each return a scalar (the amount of savings consumed) and mutate an input (transactions
). The usual style guidance for Python is to either return a value or mutate (c.f. https://stackoverflow.com/questions/26027694/correct-style-for-python-functions-that-mutate-the-argument), and to only mutate the leftmost input.Consider how to address this in the context of these methods. Since they are underscored (quasi-private) methods, consider returning a tuple of
(available_consumed, further_transactions)
. (Note: this, in combination with usingdict.get(key, default)
, will help make the logic of these methods cleaner, since there's no need to fill out the keys.) Calling methods will need to add thefurther_transactions
to theirtransactions
dict, which might be a bit slower than mutating, but it will be clearer for reading and debugging.Suggested method signature:
_assign_available(debt: Debt, transactions: dict[Debt, Money], when: Decimal) -> (Money, dict[Debt, Money])