diff --git a/src/commons/addr/geo.py b/src/commons/addr/geo.py index 4d11443..fab1ddf 100644 --- a/src/commons/addr/geo.py +++ b/src/commons/addr/geo.py @@ -58,9 +58,13 @@ def _parse_ipify(data: dict) -> Optional[str]: return ip or None -def _state_slug(state: str) -> str: - """lowercase ascii-folded state slug with underscores (e.g. 'New York' -> 'new_york')""" - folded = unicodedata.normalize("NFKD", state).encode("ascii", "ignore").decode("ascii") +def _state_slug(state) -> str: + """lowercase ascii-folded state slug with underscores (e.g. 'New York' -> 'new_york') + + coerces to str first so a malformed non-string `state` doesn't raise TypeError out + of unicodedata.normalize and break the 'None on any parse failure' contract. + """ + folded = unicodedata.normalize("NFKD", str(state)).encode("ascii", "ignore").decode("ascii") return folded.lower().replace(" ", "_")