Why this matters
Prevents surprising side effects and makes functions safer to reuse.
Treat function inputs as immutable; copy before mutation (e.g., dict.copy(), list(x)).
Prevents surprising side effects and makes functions safer to reuse.
Side-by-side examples engineers can pattern-match during review.
def normalize(d: dict) -> dict:
d['status'] = d['status'].lower()
return ddef normalize(d: dict) -> dict:
out = {**d}
out['status'] = out.get('status', '').lower()
return outdef f(x): x.append(1); return xdef f(xs): ys = list(xs); ys.append(1); return ysFrom the same buckets as this rule.