From 12cf07919f2617de34acabbf85b27db775657297 Mon Sep 17 00:00:00 2001 From: disqualifier Date: Mon, 29 Jun 2026 21:34:40 -0400 Subject: [PATCH] fix: C1 coerce non-str state in _state_slug so geo parse can't TypeError a malformed non-string 'state' reached unicodedata.normalize and raised TypeError out of fetch_location, breaking the 'None on any parse failure' contract; str() it first. Signed-off-by: disqualifier --- src/commons/addr/geo.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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(" ", "_")