LXML should respect case of infinity and NaN for XML Schema conformance

Bug #1960715 reported by Haxtibal
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
lxml
Fix Released
Low
scoder

Bug Description

lxml.objectify XSI-annotates Python float as xsd:double. W3Cs XML Schema Datatype specification for double [0] says:

> The special values positive and negative infinity and not-a-number have lexical representations INF, -INF and NaN, respectively.

Thus case matters
- "INF","-INF", "NaN" are valid
- but lxml.objectify generates "inf", "-inf", "nan", which are invalid

Reproducer:

from lxml import etree, objectify
root = objectify.ElementMaker(annotate=False).test(float("inf"))
objectify.xsiannotate(root)
print(etree.tostring(root, pretty=True).decode())

gives

<test xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="xsd:double">inf</test>

xmllint (as well as multiple other schema validators I've tested) will correctly detect the error:

Schemas validity error : Element 'test': 'inf' is not a valid value of the atomic type 'xs:double'.

[0] https://www.w3.org/TR/xmlschema-2/#double

lxml.etree : (4, 7, 1, 0)
libxml used : (2, 9, 4)
libxml compiled : (2, 9, 4)
libxslt used : (1, 1, 33)
libxslt compiled : (1, 1, 33)

Revision history for this message
scoder (scoder) wrote :
Changed in lxml:
assignee: nobody → scoder (scoder)
importance: Undecided → Low
milestone: none → 4.9.0
status: New → Fix Committed
Revision history for this message
scoder (scoder) wrote :
scoder (scoder)
Changed in lxml:
milestone: 4.9.0 → 4.8.0
scoder (scoder)
Changed in lxml:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.