Fix infinite recursion when __repr__ is called
Also add some more tests.
@@ -141,7 +141,7 @@ class Namespace(str):
return self.term(name)
def __repr__(self):
- return f"Namespace({self!r})"
+ return f"Namespace({super().__repr__()})"
def __contains__(self, ref):
"""Allows to check if a URI is within (starts with) this Namespace.
@@ -187,7 +187,7 @@ class URIPattern(str):
return URIRef(super().format(*args, **kwargs))
def __repr__(self):
- return f"URIPattern({self!r})"
+ return f"URIPattern({super().__repr__()})"
class ClosedNamespace(Namespace):
@@ -199,6 +199,7 @@ class ClosedNamespace(Namespace):
def __new__(cls, uri, terms):
rt = super().__new__(cls, uri)
+ rt.__terms = terms
rt.__uris = {t: URIRef(rt + t) for t in terms}
return rt
@@ -225,7 +226,7 @@ class ClosedNamespace(Namespace):
raise AttributeError(e)
def __repr__(self):
- return f"{self.__module__}.{self.__class__.__name__}({self!r})"
+ return f"{self.__module__}.{self.__class__.__name__}({str(self)!r})"
def __dir__(self):
return list(self.__uris)
