diff --git a/conservancy_beancount/data.py b/conservancy_beancount/data.py index 86a06c7f57c808309019c954603f8997481d7124..b6903d30ec98aae486514d2e41efd997baa5eab9 100644 --- a/conservancy_beancount/data.py +++ b/conservancy_beancount/data.py @@ -132,6 +132,15 @@ class Amount(bc_amount.Amount): """ number: decimal.Decimal + # beancount.core._Amount is the plain namedtuple. + # beancore.core.Amount adds instance methods to it. + # b.c.Amount.__New__ calls `b.c._Amount.__new__`, which confuses type + # checking. See . + # It works fine if you use super(), which is better practice anyway. + # So we override __new__ just to call _Amount.__new__ this way. + def __new__(cls, number: decimal.Decimal, currency: str) -> 'Amount': + return super(bc_amount._Amount, Amount).__new__(cls, number, currency) + class Metadata(MutableMapping[MetaKey, MetaValue]): """Transaction or posting metadata @@ -309,7 +318,7 @@ def balance_of(txn: Transaction, ] number = sum((wt.number for wt in weights), number) currency = weights[0].currency - return Amount._make((number, currency)) + return Amount(number, currency) @functools.lru_cache() def is_opening_balance_txn(txn: Transaction) -> bool: