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: xml.etree.ElementTree.tostringlist does not conform to its documentation
Type: behavior Stage: resolved
Components: Documentation, XML Versions: Python 3.2, Python 3.3
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, einarfd, eli.bendersky, ezio.melotti, python-dev, serhiy.storchaka
Priority: normal Keywords:

Created on 2012-09-28 10:51 by einarfd, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (5)
msg171434 - (view) Author: Einar Fløystad Dørum (einarfd) Date: 2012-09-28 10:51
The tostringlist documentation says "Returns a list of (optionally) encoded strings containing the XML data. It does not guarantee any specific sequence, except that "".join(tostringlist(element)) == tostring(element).". 
But in reality it is possible to get tostringlist to return a string and not a list. 
The following code will demonstrates problem, by failing with a TypeError:

from xml.etree.ElementTree import Element, tostringlist, tostring

element = Element("foo")
print ("".join(tostringlist(element)) == tostring(element))
msg171445 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-09-28 12:06
Bug in the documentation, but not in the implementation.

See also issue8047 and issue1767933 (changeset 63845:57e631f088d7).
msg172299 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2012-10-07 13:22
Thanks for the report. I'll take a look.

Patches always welcome :)
msg172482 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2012-10-09 14:06
Einar, TypeError is raised because tostring/tostringlist return bytes with the default encoding, and you can't join bytes on "" (which is unicode).
msg172483 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2012-10-09 14:19
New changeset ff925e135e60 by Eli Bendersky in branch '3.3':
Issue #16082: clarify the documentation of tostring[list] saying that it may generate a bytestring, depending on the given encoding.
http://hg.python.org/cpython/rev/ff925e135e60

New changeset 6e407fcf7380 by Eli Bendersky in branch 'default':
Merge 3.3
http://hg.python.org/cpython/rev/6e407fcf7380
History
Date User Action Args
2022-04-11 14:57:36adminsetgithub: 60286
2012-10-09 14:19:21python-devsetstatus: open -> closed

nosy: + python-dev
messages: + msg172483

resolution: fixed
stage: patch review -> resolved
2012-10-09 14:06:27eli.benderskysetmessages: + msg172482
2012-10-07 13:22:56eli.benderskysettitle: xml.etree.ElementTree.tostringlist does conform to it's documentation -> xml.etree.ElementTree.tostringlist does not conform to its documentation
messages: + msg172299
stage: patch review
2012-09-30 16:46:13ezio.melottisetnosy: + ezio.melotti
2012-09-28 12:06:27serhiy.storchakasetversions: + Python 3.2
nosy: + eli.bendersky, docs@python, serhiy.storchaka

messages: + msg171445

assignee: docs@python
components: + Documentation
2012-09-28 10:51:26einarfdcreate