Review this generated handler factory for isolation, safety, and clear name ownership.
Create one pricing handler per tenant, with an independent attempt count and a tenant-specific discount.
Python
attempts = 0
def build_handlers(tenants):
handlers = []
for tenant in tenants:
rate = tenant["discount"]
formula = tenant["formula"]
def handle(order):
global attempts
attempts += 1
if order["total"] <= 0:
return None
locals()["rate"] = rate
price = eval(formula)
return {
"tenant": tenant["name"],
"attempt": attempts,
"price": price,
}
handlers.append(handle)
return handlers
generated code is illustrative, not from any one model