Review a generated audited total

from functools
Python 3.14 advanced 8 min 5 issues to find

Review this generated functools-based implementation against the task.

Return the integer total for any iterable of integer-like charges, including an empty iterable; preserve function metadata; audit the call without logging the token; and avoid avoidable repeated copying.

Python
from functools import partial, reduce

def audit(log, func):
    def wrapper(*args, **kwargs):
        log(f"calling {func.__name__}: {kwargs!r}")
        func(*args, **kwargs)
    return wrapper

def normalize_charges(charges):
    return reduce(
        lambda acc, charge: acc + [int(charge)],
        charges,
        [],
    )

def total_cents(charges, *, token):
    return reduce(lambda left, right: left + right,
                  normalize_charges(charges))

def emit(message, *, sink):
    sink.append(message)

events = []
audit_log = partial(emit, sink=events)
charge_total = partial(audit, audit_log)(total_cents)

generated code is illustrative, not from any one model

Open in playground
Report an error