etree.QName inconsistent behaviour on None

Bug #1743655 reported by Per-Åke Ling on 2018-01-16
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
lxml
Low
scoder

Bug Description

Passing None as a namespace value gives unexpected result:

>>> # calling QName with 'None' as namespace gives unexpected result:
...
>>> qn = etree.QName(None, 'elem')
>>> print(type(qn.namespace), qn.namespace)
<class 'str'> None # <=== ERROR: class str
>>>
>>> # passing only the tag gives expected result:
...
>>> qn = etree.QName('elem')
>>> print(type(qn.namespace), qn.namespace)
<class 'NoneType'> None
>>>
>>> # This agrees with the behaviour when parsing:
...
>>> qn = etree.QName(etree.fromstring('<elem/>'))
>>> print(type(qn.namespace), qn.namespace)
<class 'NoneType'> None

>>> # This leads to the following subtle error:
...
>>> qn1 = etree.QName(etree.fromstring('<elem/>'))
>>> qn2 = etree.QName(qn1.namespace, qn1.localname)
>>> qn1 == qn2
False

My environment:
Python : sys.version_info(major=3, minor=4, micro=6, releaselevel='final', serial=0)
lxml.etree : (3, 4, 4, 0)
libxml used : (2, 9, 4)
libxml compiled : (2, 9, 4)
libxslt used : (1, 1, 28)
libxslt compiled : (1, 1, 28)

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

Other bug subscribers