#NEWLINE# def compute_ledger_values( lazy_original_balance , report_type , quantity ) : #NEWLINE# #INDENT# "\n    lazy_original_balance:\n        a zero-argument function returning original balance\n        the original_balance is only used in the case of a transfer\n        and it may be computationally expensive for the caller to provide\n        putting it behind a function lets compute_ledger_values decide\n        whether it's necessary to do that work\n    report_type:\n        a string in VALID_REPORT_TYPES\n        says whether it's a transfer or balance\n    quantity:\n        the associated quantity, interpreted as a delta for transfers\n        and a total balance for balances\n\n    " #NEWLINE# if ( report_type == stockconst . REPORT_TYPE_BALANCE ) : #NEWLINE# #INDENT# new_balance = quantity #NEWLINE# new_delta = 0 #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( report_type == stockconst . REPORT_TYPE_TRANSFER ) : #NEWLINE# #INDENT# original_balance = lazy_original_balance ( ) #NEWLINE# new_delta = quantity #NEWLINE# new_balance = ( new_delta + ( original_balance if original_balance else 0 ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise ValueError ( ) #NEWLINE# #UNINDENT# #UNINDENT# return LedgerValues ( new_balance , new_delta )