From 3f04c82ba9a61901dd84059f557db1e0007e84b5 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Wed, 19 Jun 2024 14:40:14 +0100 Subject: [PATCH] Improve get_item_street_addresses --- matcher/api.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/matcher/api.py b/matcher/api.py index 8ebc159..97e47f1 100644 --- a/matcher/api.py +++ b/matcher/api.py @@ -941,7 +941,11 @@ def get_item(item_id: int) -> model.Item | None: def get_item_street_addresses(item: model.Item) -> list[str]: """Hunt for street addresses for the given item.""" - street_address = [addr["text"] for addr in item.get_claim("P6375") if addr] + p6375 = item.get_claim("P6375") + assert isinstance(p6375, list) + street_address: list[str] = [ + typing.cast(str, addr["text"]) for addr in p6375 if addr + ] if street_address or "P669" not in item.claims: return street_address @@ -951,8 +955,8 @@ def get_item_street_addresses(item: model.Item) -> list[str]: qualifiers = claim.get("qualifiers") if not qualifiers or "P670" not in qualifiers: continue - if "datavalue" not in qualifiers["P670"][0]: - print(f"datavalue missing in P670 for {item.qid}") + if "datavalue" not in qualifiers["P670"][0]: # 'no value' for P670 + assert qualifiers["P670"][0]["snaktype"] == "novalue" continue number = qualifiers["P670"][0]["datavalue"]["value"]