question 362 Profiling & Optimization · easy
Fix the cached shipping quote
A checkout caches shipping quotes because computing one is slow. Since @cache was added, every checkout crashes with TypeError: unhashable type: 'list'. Fix it so the quote is still cached, and callers can keep passing the cart's weights as a list.
Function
shipping_quote(weights, zone) (called with a list of weights in kg and a zone name)Returns
5.99 plus 1.25 per kg of total weight for "domestic", 24.0 plus 3.5 per kg otherwiseRulerepeated quotes for the same weights and zone are computed once
Examples
callshipping_quote([2.75, 0.3], 'domestic')returns9.8025
callshipping_quote([1], 'international')returns27.5
callshipping_quote([], 'domestic')returns5.99