Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into cwa/fix-306-ontodoc…
Browse files Browse the repository at this point in the history
…-rdflib-import
  • Loading branch information
CasperWA committed Dec 2, 2021
2 parents 118d3b6 + dce92c0 commit f908df2
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion ontopy/ontology.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,9 @@ def _unabbreviate(i):
_unabbreviate(obj),
)

def get_by_label(self, label, label_annotations=None, namespace=None):
def get_by_label(
self, label, label_annotations=None, namespace=None
): # pylint: disable=too-many-arguments,too-many-branches
"""Returns entity with label annotation `label`.
`label_annotations` is a sequence of label annotation names to look up.
Expand All @@ -256,6 +258,15 @@ def get_by_label(self, label, label_annotations=None, namespace=None):
The current implementation also supports "*" as a wildcard
matching any number of characters. This may change in the future.
"""
if not isinstance(label, str):
raise TypeError(
f"Invalid label definition, must be a string: {label!r}"
)
if " " in label:
raise ValueError(
f"Invalid label definition, {label!r} contains spaces."
)

if "namespaces" in self.__dict__:
if namespace:
if namespace in self.namespaces:
Expand Down Expand Up @@ -296,6 +307,15 @@ def get_by_label_all(self, label, label_annotations=None, namespace=None):
Returns an empty list if no matches could be found.
"""
if not isinstance(label, str):
raise TypeError(
f"Invalid label definition, " f"must be a string: {label!r}"
)
if " " in label:
raise ValueError(
f"Invalid label definition, {label!r} contains spaces."
)

if label_annotations is None:
annotations = (_.name for _ in self.label_annotations)
else:
Expand Down

0 comments on commit f908df2

Please sign in to comment.