diff options
author | shreyasnagare <shreyasnagare@gmail.com> | 2021-06-30 19:35:08 -0400 |
---|---|---|
committer | shreyasnagare <shreyasnagare@gmail.com> | 2021-06-30 19:35:08 -0400 |
commit | db531bf65a7780204d670387affdb5d14fcd4d91 (patch) | |
tree | bfb6657ee34102b66a0c4e0acc649c1d5804af55 | |
parent | 529caa24feca237ae31b84adabb7c90c2805ba83 (diff) | |
download | rdflib-db531bf65a7780204d670387affdb5d14fcd4d91.tar.gz |
Add fallback for subclasses with required init args
-rw-r--r-- | rdflib/graph.py | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/rdflib/graph.py b/rdflib/graph.py index c354a770..8cbc066d 100644 --- a/rdflib/graph.py +++ b/rdflib/graph.py @@ -558,7 +558,10 @@ class Graph(Node): def __add__(self, other): """Set-theoretic union BNode IDs are not changed.""" - retval = self.__class__() + 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.""" - retval = self.__class__() + 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.""" - retval = self.__class__() + try: + retval = self.__class__() + except TypeError: + retval = Graph() for x in self: if x not in other: retval.add(x) |