summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornicholascar <nicholas.car@surroundaustralia.com>2021-12-09 15:29:15 +1000
committernicholascar <nicholas.car@surroundaustralia.com>2021-12-09 15:29:15 +1000
commitdabcacf3bfda83715e3bc4afb85d10e7ae2630ce (patch)
tree5f63ee0600b63d1f9820776abf296bdeb8bd98df
parent0891e2eab5ddf1ba2609edf7c74a2398fa2440c5 (diff)
downloadrdflib-hextuples.tar.gz
fixing MyPy errorshextuples
-rw-r--r--rdflib/plugins/parsers/hext.py8
-rw-r--r--rdflib/plugins/serializers/hext.py2
2 files changed, 9 insertions, 1 deletions
diff --git a/rdflib/plugins/parsers/hext.py b/rdflib/plugins/parsers/hext.py
index b61fc0e4..59e045cf 100644
--- a/rdflib/plugins/parsers/hext.py
+++ b/rdflib/plugins/parsers/hext.py
@@ -27,7 +27,14 @@ class HextuplesParser(Parser):
return [x if x != "" else None for x in json.loads(line)]
def _parse_hextuple(self, cg: ConjunctiveGraph, tup: List[Union[str, None]]):
+ # all values check
+ # subject, predicate, value, datatype cannot be None
+ # language and graph may be None
+ if tup[0] is None or tup[1] is None or tup[2] is None or tup[3] is None:
+ raise ValueError("subject, predicate, value, datatype cannot be None")
+
# 1 - subject
+ s: Union[URIRef, BNode]
if tup[0].startswith("_"):
s = BNode(value=tup[0].replace("_:", ""))
else:
@@ -37,6 +44,7 @@ class HextuplesParser(Parser):
p = URIRef(tup[1])
# 3 - value
+ o: Union[URIRef, BNode, Literal]
if tup[3] == "globalId":
o = URIRef(tup[2])
elif tup[3] == "localId":
diff --git a/rdflib/plugins/serializers/hext.py b/rdflib/plugins/serializers/hext.py
index 858e2d4e..c86882a2 100644
--- a/rdflib/plugins/serializers/hext.py
+++ b/rdflib/plugins/serializers/hext.py
@@ -19,7 +19,7 @@ class HextuplesSerializer(Serializer):
def __init__(self, store: Union[Graph, ConjunctiveGraph]):
self.default_context: Optional[Node]
- if type(store) != Graph:
+ if isinstance(store, ConjunctiveGraph):
self.contexts = list(store.contexts())
if store.default_context:
self.default_context = store.default_context