Consider the Python snippet below.
"""
import math
def accumulate(nums, start=0, cache={}):
total = start
for n in nums:
if n % 2 == 0:
nums.append(n//2)
total += n
cache[str(nums)] = total
return total
"""
Tasks:
-
Precisely state what accumulate([2, 3], start=1) returns and why (walk through iteration order and mutations). Identify every bug/code smell (logical, algorithmic, and design) and their impact: list-mutation during iteration, default-mutable arguments, potential non-termination, unintended cache growth, time/space complexity, and keying strategy.
-
Provide a corrected, production-ready version (pure function + optional caching) with asymptotic complexity analysis and docstring that specifies pre/post-conditions.
-
Write minimal but thorough pytest unit tests (property-based or table-driven) covering edge cases (empty list, very large even chains, negatives, None, non-ints) and proving termination.
-
Show exact commands to: create/activate an isolated virtual environment; pin dependencies; run tests; and produce a wheel. Assume macOS/Linux.
-
Briefly explain how you would add CI (static type checks with mypy, linting, coverage thresholds) and package an entry-point CLI.