From dabcacf3bfda83715e3bc4afb85d10e7ae2630ce Mon Sep 17 00:00:00 2001 From: nicholascar Date: Thu, 9 Dec 2021 15:29:15 +1000 Subject: [PATCH] fixing MyPy errors --- rdflib/plugins/parsers/hext.py | 8 ++++++++ rdflib/plugins/serializers/hext.py | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/rdflib/plugins/parsers/hext.py b/rdflib/plugins/parsers/hext.py index b61fc0e43..59e045cf4 100644 --- a/rdflib/plugins/parsers/hext.py +++ b/rdflib/plugins/parsers/hext.py @@ -27,7 +27,14 @@ def _load_json_line(self, line: str): 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 @@ def _parse_hextuple(self, cg: ConjunctiveGraph, tup: List[Union[str, None]]): 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 858e2d4e8..c86882a2b 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