Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chain function must not corrupt the argument #62

Closed
epogrebnyak opened this issue Dec 17, 2023 · 1 comment
Closed

chain function must not corrupt the argument #62

epogrebnyak opened this issue Dec 17, 2023 · 1 comment

Comments

@epogrebnyak
Copy link
Owner

abacus/x/test_compose.py

Lines 141 to 147 in 1bd402b

def test_chain_must_not_corrupt_the_argument(chart_list, ledger0):
_, _ = chain(
chart_list, ledger0, [close_first, close_second, close_last]
)
assert ledger0.data["salaries"].debit_and_credit() == (2001, 0)
assert ledger0.data["sales"].debit_and_credit() == (0, 3499)
assert ledger0.data["refunds"].debit_and_credit() == (499, 0)

Here is how chain() works:

abacus/x/compose.py

Lines 389 to 397 in 1bd402b

def chain(chart, ledger, functions):
# this line is expected to make deep copy of ledger instance
# apparently this does not work
_ledger = ledger.condense() # .deep_copy()
closing_entries = []
for f in functions:
_ledger, entries = f(chart, _ledger)
closing_entries += entries
return _ledger, closing_entries

I tried both ledger.condense() and ledger.deepcopy() none of them create a copy of ledger as expected.

The expected bevaviout is that after running the chain function the ledger argument is not changed!

@epogrebnyak
Copy link
Owner Author

The example can eb run at https://github.com/epogrebnyak/abacus/blob/main/x/using.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant