From 5691a26441b0f7bc5ad840e0c263559433125d1b Mon Sep 17 00:00:00 2001 From: eprbell <77937475+eprbell@users.noreply.github.com> Date: Fri, 15 Nov 2024 19:36:55 -0800 Subject: [PATCH] Improved some comments --- src/rp2/abstract_accounting_method.py | 2 +- src/rp2/accounting_engine.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/rp2/abstract_accounting_method.py b/src/rp2/abstract_accounting_method.py index d15992d..ba2886a 100644 --- a/src/rp2/abstract_accounting_method.py +++ b/src/rp2/abstract_accounting_method.py @@ -261,7 +261,7 @@ def seek_non_exhausted_acquired_lot( if not isinstance(lot_candidates, FeatureBasedAcquiredLotCandidates): raise RP2TypeError(f"Internal error: lot_candidates is not of type FeatureBasedAcquiredLotCandidates, but of type {type(lot_candidates)}") # This plugin features O(n * log(m)) complexity, where n is the number - # of transactions and m is the number of unexhausted acquistion lots + # of transactions and m is the number of unexhausted acquisition lots for acquired_lot in lot_candidates: acquired_lot_amount: RP2Decimal = ZERO diff --git a/src/rp2/accounting_engine.py b/src/rp2/accounting_engine.py index 4999238..07ec646 100644 --- a/src/rp2/accounting_engine.py +++ b/src/rp2/accounting_engine.py @@ -174,7 +174,7 @@ def get_next_taxable_event_and_amount( new_taxable_event_amount: RP2Decimal = new_taxable_event.crypto_balance_change # If the new taxable event is newer than the old one (and it's not earn-typed) check if there is a newer acquired lot that - # meets the accounting method criteria (but it's still older than the new taxable event) + # meets the accounting method criteria (but it's still older than the new taxable event). if taxable_event and taxable_event.timestamp < new_taxable_event.timestamp: if acquired_lot: self._set_partial_amount(acquired_lot, new_acquired_lot_amount) @@ -189,8 +189,7 @@ def get_next_taxable_event_and_amount( acquired_lot_amount=new_acquired_lot_amount, ) - # After selecting the taxable event, RP2 calls this function to find the acquired_lot to pair with it. This means that the taxable - # event can be passed to this function (which is useful for certain accounting methods) + # After selecting the taxable event, RP2 calls this function to find the acquired_lot to pair with it. def get_acquired_lot_for_taxable_event( self, taxable_event: AbstractTransaction, @@ -199,6 +198,8 @@ def get_acquired_lot_for_taxable_event( acquired_lot_amount: RP2Decimal, ) -> TaxableEventAndAcquiredLot: new_taxable_event_amount: RP2Decimal = taxable_event_amount - acquired_lot_amount + # Find the acquired_lot and index just before the taxable event: the index is used as an upper bound + # in the search of acquired lot candidates (see set_to_index() below). acquired_lot_and_index: Optional[_AcquiredLotAndIndex] = self.__acquired_lot_avl.find_max_value_less_than( self._get_avl_node_key_with_max_disambiguator(taxable_event.timestamp) )