Complete worked example
python
def settings(values):
country = values.get("COUNTRY", "US")
limit = values.get("LIMIT", "2")
if not isinstance(country, str) or not isinstance(limit, str):
raise ValueError("settings must be strings")
country = country.strip().upper()
if country not in {"US", "IL", "UA", "CA"}:
raise ValueError("unsupported country")
if not limit.isascii() or not limit.isdecimal() or not 1 <= int(limit) <= 5:
raise ValueError("limit must be 1..5")
return {"country": country, "limit": int(limit)}- Reasoning
- Turn environment-style strings into a small validated configuration without reading ambient process state. Compare the stated values and failure boundary before changing the implementation.