Skip to content

Commit 3cbfcf2

Browse files
committed
notation3.py: don't normalize float representation
fix behavior of the n3 parser family to avoid normalizing raw float string representation which makes it impossible to roundtrip the exact original string representation of e.g. 1e10
1 parent 9b3f790 commit 3cbfcf2

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

rdflib/plugins/parsers/notation3.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,10 @@ def unicodeExpand(m: Match) -> str:
380380
langcode = re.compile(r"[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*")
381381

382382

383+
class sfloat(str):
384+
""" don't normalize raw XSD.double string representation """
385+
386+
383387
class SinkParser:
384388
def __init__(
385389
self,
@@ -1528,7 +1532,7 @@ def nodeOrLiteral(self, argstr: str, i: int, res: MutableSequence[Any]) -> int:
15281532
m = exponent_syntax.match(argstr, i)
15291533
if m:
15301534
j = m.end()
1531-
res.append(float(argstr[i:j]))
1535+
res.append(sfloat(argstr[i:j]))
15321536
return j
15331537

15341538
m = decimal_syntax.match(argstr, i)
@@ -1911,7 +1915,7 @@ def makeStatement(
19111915
def normalise(
19121916
self,
19131917
f: Optional[Formula],
1914-
n: Union[Tuple[int, str], bool, int, Decimal, float, _AnyT],
1918+
n: Union[Tuple[int, str], bool, int, Decimal, sfloat, _AnyT],
19151919
) -> Union[URIRef, Literal, BNode, _AnyT]:
19161920
if isinstance(n, tuple):
19171921
return URIRef(str(n[1]))
@@ -1931,7 +1935,7 @@ def normalise(
19311935
s = Literal(value, datatype=DECIMAL_DATATYPE)
19321936
return s
19331937

1934-
if isinstance(n, float):
1938+
if isinstance(n, sfloat):
19351939
s = Literal(str(n), datatype=DOUBLE_DATATYPE)
19361940
return s
19371941

0 commit comments

Comments
 (0)