diff options
author | Iwan Aucamp <aucampia@gmail.com> | 2022-01-09 14:38:23 +0100 |
---|---|---|
committer | Iwan Aucamp <aucampia@gmail.com> | 2022-01-09 14:38:23 +0100 |
commit | f5736e5284ca60d8ab5a52e6373e3f5af85899cb (patch) | |
tree | 8632a9fb8ccaad4efc044d6803795428ba54a404 | |
parent | 2c5b50993d58a65c800bf337eb3c5c718b3a0410 (diff) | |
download | rdflib-f5736e5284ca60d8ab5a52e6373e3f5af85899cb.tar.gz |
One typing fix and removal of redundant casts
-rw-r--r-- | rdflib/plugins/parsers/hext.py | 14 | ||||
-rw-r--r-- | rdflib/plugins/serializers/hext.py | 3 |
2 files changed, 7 insertions, 10 deletions
diff --git a/rdflib/plugins/parsers/hext.py b/rdflib/plugins/parsers/hext.py index 184d77a9..670baea4 100644 --- a/rdflib/plugins/parsers/hext.py +++ b/rdflib/plugins/parsers/hext.py @@ -5,7 +5,7 @@ handle contexts, i.e. multiple graphs. """ import json -from typing import List, Union, cast +from typing import List, Union from rdflib.parser import Parser from rdflib import ConjunctiveGraph, URIRef, Literal, BNode import warnings @@ -47,7 +47,7 @@ class HextuplesParser(Parser): if tup[0].startswith("_"): s = BNode(value=tup[0].replace("_:", "")) else: - s = cast(URIRef, URIRef(tup[0])) + s = URIRef(tup[0]) # 2 - predicate p = URIRef(tup[1]) @@ -55,18 +55,14 @@ class HextuplesParser(Parser): # 3 - value o: Union[URIRef, BNode, Literal] if tup[3] == "globalId": - o = cast(URIRef, URIRef(tup[2])) + o = URIRef(tup[2]) elif tup[3] == "localId": o = BNode(value=tup[2].replace("_:", "")) else: # literal if tup[4] is None: - o = cast( - Literal, - Literal(tup[2], datatype=URIRef(tup[3]))) + o = Literal(tup[2], datatype=URIRef(tup[3])) else: - o = cast( - Literal, - Literal(tup[2], lang=tup[4])) + o = Literal(tup[2], lang=tup[4]) # 6 - context if tup[5] is not None: diff --git a/rdflib/plugins/serializers/hext.py b/rdflib/plugins/serializers/hext.py index 6a57a263..3fdf3684 100644 --- a/rdflib/plugins/serializers/hext.py +++ b/rdflib/plugins/serializers/hext.py @@ -2,7 +2,7 @@ HextuplesSerializer RDF graph serializer for RDFLib. See <https://github.com/ontola/hextuples> for details about the format. """ -from typing import IO, Optional, Union +from typing import IO, Optional, Type, Union import json from rdflib.graph import Graph, ConjunctiveGraph from rdflib.term import Literal, URIRef, Node, BNode @@ -20,6 +20,7 @@ class HextuplesSerializer(Serializer): def __init__(self, store: Union[Graph, ConjunctiveGraph]): self.default_context: Optional[Node] + self.graph_type: Type[Graph] if isinstance(store, ConjunctiveGraph): self.graph_type = ConjunctiveGraph self.contexts = list(store.contexts()) |