summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornicholascar <nicholas.car@surroundaustralia.com>2021-12-07 16:15:51 +1000
committernicholascar <nicholas.car@surroundaustralia.com>2021-12-07 16:15:51 +1000
commit75b797e0aacdd098d5ad7c863fc628d468f4dfe9 (patch)
tree86f4e5bd3744f2bc3fe2e6286cb124ded6431ab1
parent7f3f5b6eb11e10e7355bed9f2dd8892a499e4410 (diff)
downloadrdflib-75b797e0aacdd098d5ad7c863fc628d468f4dfe9.tar.gz
isinstance() instead of type()
-rw-r--r--rdflib/plugins/serializers/hext.py18
1 files changed, 9 insertions, 9 deletions
diff --git a/rdflib/plugins/serializers/hext.py b/rdflib/plugins/serializers/hext.py
index cec695b2..456dd014 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, TYPE_CHECKING, Optional, Union
+from typing import IO, Optional, Union
from rdflib.graph import Graph, ConjunctiveGraph
from rdflib.term import Literal, URIRef, Node, BNode
from rdflib.serializer import Serializer
@@ -56,20 +56,20 @@ class HextuplesSerializer(Serializer):
stream.write(hl.encode())
def _hex_line(self, triple, context):
- if type(triple[0]) in [URIRef, BNode]: # exclude QuotedGraph and other objects
+ if isinstance(triple[0], (URIRef, BNode)): # exclude QuotedGraph and other objects
# value
value = triple[2] \
- if type(triple[2]) == Literal \
+ if isinstance(triple[2], Literal) \
else self._iri_or_bn(triple[2])
# datatype
- if type(triple[2]) == URIRef:
+ if isinstance(triple[2], URIRef):
# datatype = "http://www.w3.org/1999/02/22-rdf-syntax-ns#namedNode"
datatype = "globalId"
- elif type(triple[2]) == BNode:
+ elif isinstance(triple[2], BNode):
# datatype = "http://www.w3.org/1999/02/22-rdf-syntax-ns#blankNode"
datatype = "localId"
- elif type(triple[2]) == Literal:
+ elif isinstance(triple[2], Literal):
if triple[2].datatype is not None:
datatype = f"{triple[2].datatype}"
else:
@@ -81,7 +81,7 @@ class HextuplesSerializer(Serializer):
return None # can't handle non URI, BN or Literal Object (QuotedGraph)
# language
- if type(triple[2]) == Literal:
+ if isinstance(triple[2], Literal):
if triple[2].language is not None:
language = f"{triple[2].language}"
else:
@@ -101,9 +101,9 @@ class HextuplesSerializer(Serializer):
return None
def _iri_or_bn(self, i_):
- if type(i_) == URIRef:
+ if isinstance(i_, URIRef):
return f"{i_}"
- elif type(i_) == BNode:
+ elif isinstance(i_, BNode):
return f"{i_.n3()}"
else:
return None