This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: ElementTree QName has a very uninformative repr()
Type: behavior Stage:
Components: Versions:
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: eric.smith, exarkun, georg.brandl
Priority: normal Keywords:

Created on 2010-12-09 16:54 by exarkun, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (4)
msg123687 - (view) Author: Jean-Paul Calderone (exarkun) * (Python committer) Date: 2010-12-09 16:54
This is somewhat unfortunate behavior:

>>> from xml.etree.ElementTree import QName
>>> QName('foo')
<xml.etree.ElementTree.QName instance at 0x10049c830>
>>> 

It becomes even more apparent when encountered in a situation like this:

>>> print {QName('foo'): 'bar', QName('baz'): 'quux'}
{<xml.etree.ElementTree.QName instance at 0x10049cb90>: 'bar', <xml.etree.ElementTree.QName instance at 0x10049c248>: 'quux'}
>>> 

I would like to see QName.__repr__ return something like '<QName %r>' % (text,)
msg123690 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-12-09 18:10
Added in r87147.
msg123691 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2010-12-09 18:22
This should be either:
'<QName %r>' % (self.text,)
or:
'<QName {!r}>'.format(self.text)

If self.text is a tuple (which granted is its own error), then the version checked in will raise an exception.
msg123692 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-12-09 18:26
Granted.  Since the rest of the file uses old-style format, I've kept to it, r87148.
History
Date User Action Args
2022-04-11 14:57:10adminsetgithub: 54870
2010-12-09 18:26:31georg.brandlsetstatus: open -> closed

messages: + msg123692
2010-12-09 18:22:36eric.smithsetstatus: closed -> open

nosy: + eric.smith
messages: + msg123691

resolution: fixed ->
2010-12-09 18:10:44georg.brandlsetstatus: open -> closed

nosy: + georg.brandl
messages: + msg123690

resolution: fixed
2010-12-09 16:54:08exarkuncreate