Raise exception if prefix not bound, expand exception message, add test of objects/messages.
@@ -600,10 +600,11 @@ class NamespaceManager(object):
>>> g.namespace_manager.expand_curie("rdf:type")
rdflib.term.URIRef('http://www.w3.org/1999/02/22-rdf-syntax-ns#type')
- Returns `None` if a namespace is not bound to the prefix.
+ Raises exception if a namespace is not bound to the prefix.
+
"""
if not type(curie) is str:
- raise TypeError("Argument must be a string.")
+ raise TypeError(f"Argument must be a string, not {type(curie).__name__}.")
parts = curie.split(":", 1)
if len(parts) != 2 or len(parts[0]) < 1:
raise ValueError(
@@ -612,7 +613,10 @@ class NamespaceManager(object):
ns = self.store.namespace(parts[0])
if ns is not None:
return URIRef(f"{str(ns)}{parts[1]}")
- return None
+ else:
+ raise ValueError(
+ f"Prefix \"{curie.split(':')[0]}\" not bound to any namespace."
+ )
def bind(
self,
