Skip to content

Commit

Permalink
Update struct.py
Browse files Browse the repository at this point in the history
  • Loading branch information
cthoyt committed Jan 13, 2025
1 parent 21ebc67 commit a9eac92
Showing 1 changed file with 29 additions and 26 deletions.
55 changes: 29 additions & 26 deletions src/bioregistry/schema/struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,18 +755,20 @@ def get_prefix_key(
return cast(X, rv)
return None

def _get_prefix_key_str(self, key: str, metaprefixes: Union[str, Sequence[str]]) -> str | None:
rv = self.get_prefix_key(key, metaprefixes)
def _get_prefix_key_str(
self, key: str, metaprefixes: Union[str, Sequence[str]], *, provenance: bool = False
) -> Union[None, str, ValuePackage[str]]:
rv = self.get_prefix_key(key, metaprefixes, rv_type=str, provenance=False)
if rv is None:
return None
if isinstance(rv, str):
return rv
raise TypeError

def _get_prefix_key_bool(
self, key: str, metaprefixes: Union[str, Sequence[str]]
) -> bool | None:
rv = self.get_prefix_key(key, metaprefixes)
self, key: str, metaprefixes: Union[str, Sequence[str]], *, provenance: bool = False
) -> Union[None, bool, ValuePackage[bool]]:
rv = self.get_prefix_key(key, metaprefixes, rv_type=bool, provenance=provenance)
if rv is None:
return None
if isinstance(rv, bool):
Expand Down Expand Up @@ -984,7 +986,7 @@ def get_description(self, use_markdown: bool = False) -> Optional[str]:
"lov",
"re3data",
)
rv = self.get_prefix_key("description", metaprefixes, rv_type=str, provenance=False)
rv = self._get_prefix_key_str("description", metaprefixes, provenance=False)
if rv is not None:
return rv
if self.cellosaurus and "category" in self.cellosaurus:
Expand Down Expand Up @@ -1099,28 +1101,29 @@ def get_namespace_in_lui(self, *, provenance: bool = False) -> Optional[bool]:

def get_homepage(self) -> Optional[str]:
"""Return the homepage, if available."""
metaprefixes: Sequence[str] = [
"obofoundry",
"ols",
"miriam",
"n2t",
"wikidata",
"go",
"ncbi",
"cellosaurus",
"prefixcommons",
"fairsharing",
"cropoct",
"bioportal",
"agroportal",
"ecoportal",
"rrid",
"bartoc",
"lov",
"re3data",
]
return self._get_prefix_key_str(
"homepage",
(
"obofoundry",
"ols",
"miriam",
"n2t",
"wikidata",
"go",
"ncbi",
"cellosaurus",
"prefixcommons",
"fairsharing",
"cropoct",
"bioportal",
"agroportal",
"ecoportal",
"rrid",
"bartoc",
"lov",
"re3data",
),
metaprefixes,
)

def get_keywords(self) -> List[str]:
Expand Down

0 comments on commit a9eac92

Please sign in to comment.