Add fallback for subclasses with required init args
@@ -558,7 +558,10 @@ class Graph(Node):
def __add__(self, other):
"""Set-theoretic union
BNode IDs are not changed."""
+ try:
retval = self.__class__()
+ except TypeError:
+ retval = Graph()
for (prefix, uri) in set(list(self.namespaces()) + list(other.namespaces())):
retval.bind(prefix, uri)
for x in self:
@@ -570,7 +573,10 @@ class Graph(Node):
def __mul__(self, other):
"""Set-theoretic intersection.
BNode IDs are not changed."""
+ try:
retval = self.__class__()
+ except TypeError:
+ retval = Graph()
for x in other:
if x in self:
retval.add(x)
@@ -579,7 +585,10 @@ class Graph(Node):
def __sub__(self, other):
"""Set-theoretic difference.
BNode IDs are not changed."""
+ try:
retval = self.__class__()
+ except TypeError:
+ retval = Graph()
for x in self:
if x not in other:
retval.add(x)
