From 0ed3d3c761ec247483586cef06f47d821fde73f2 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Sun, 14 May 2023 20:29:09 +0000 Subject: [PATCH] Type hints and docstrings. --- matcher/model.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/matcher/model.py b/matcher/model.py index 4c65671..eddb447 100644 --- a/matcher/model.py +++ b/matcher/model.py @@ -107,7 +107,7 @@ class Item(Base): def get_claim(self, pid: str) -> list[dict[str, Any] | None]: """List of claims for given Wikidata property ID.""" - claims = typing.cast(dict[str, list[dict[str, Any]]], self.claims) + claims = typing.cast(wikidata.Claims, self.claims) return [ i["mainsnak"]["datavalue"]["value"] if "datavalue" in i["mainsnak"] @@ -221,10 +221,12 @@ class Item(Base): return dict(d) or None - def get_isa(self): + def get_isa(self) -> list[dict[str, int | str]]: + """Get item IDs of IsA items for this item.""" isa_list = [] of_property = "P642" - for claim in self.claims.get("P31", []): + claims = typing.cast(wikidata.Claims, self.claims) + for claim in claims.get("P31", []): qualifiers = claim.get("qualifiers", {}) if "datavalue" in claim["mainsnak"]: isa_list.append(claim["mainsnak"]["datavalue"]["value"])