Create a snapshot before clearing a successfully checked-out cart.
Checkout coordinates two existing operations: capture the purchase, then clear the working cart. Check emptiness first. If snapshot creation fails, clearing must not happen. This service returns the order to its caller; it does not register or track it yet. Keeping that boundary explicit avoids requiring the registry before you have built it. Checkout is an in-memory exercise, not a payment operation.
The empty-cart check belongs here rather than in snapshot_order: a snapshot can describe an empty state, but a purchase needs at least one line. Returning the created Order gives the next layer a value it can register and display, without making checkout depend on that layer.
The archive example copies the pending values before clearing them.
pending = ["draft"]
archived = tuple(pending)
pending.clear()
print(archived, pending)
CheckoutService.checkout(cart, order_id) to raise ValueError("cart is empty") for an empty cart; otherwise create a snapshot, clear cart lines only after creation succeeds, and return the order.Edit main.py, then press Run. The supplied probe catches unfinished-code errors so you can inspect the Console before submitting. The finished probe prints an order followed by an empty cart. Press Submit to check the behavior with other inputs.
Create the Order before calling cart.lines.clear().