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.findtext() returns empty bytes object instead of empty string
Type: behavior Stage: resolved
Components: XML Versions: Python 3.2, Python 3.3, Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: eli.bendersky, python-dev, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2013-01-10 18:10 by serhiy.storchaka, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
etree_finditer_empty-3.3.patch serhiy.storchaka, 2013-01-12 16:43 review
etree_finditer_empty-3.2.patch serhiy.storchaka, 2013-01-13 08:19 review
Messages (10)
msg179580 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-01-10 18:10
>>> import xml.etree.cElementTree as ET
>>> ET.XML('<root><empty /></root>').findtext('empty')
b''
msg179581 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-01-10 18:14
I see yet one possible bug, using PyBytes_FromString() in list_join() on 3.2. But I can't demonstrate an example.
msg179794 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2013-01-12 13:58
The fix looks good, but please don't add tests to the doctests - they are deprecated (from 3.3)
msg179799 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-01-12 14:28
But all findtext tests are doctests and I want to keep the tests together. I think there should be separated issue for converting ElementTree doctests to unittests.
msg179800 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2013-01-12 14:38
Serhiy, indeed - that's issue #15083.

But since rewriting all tests is a large task no one is willing to take at this point, my strategy has been incremental: rewrite a chunk at a time when tests are being touched. Just adding new doctests goes against the desired direction.

I'll convert the findtext tests to unittest in 3.3 and default and then you can add your new tests in the proper place. Stay tuned.
msg179817 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2013-01-12 15:46
Tests ported in 3.3 and 3.4
msg179824 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-01-12 16:43
Here is a patch for 3.3+.
msg179836 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2013-01-12 22:23
PyUnicode_New has been added in 3.3, so the 3.2 patch doesn't compile.
msg179848 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-01-13 08:19
Indeed. Patch updated.
msg179872 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-01-13 13:26
New changeset 849eb27baf1c by Eli Bendersky in branch '3.2':
Issue #16922: fixed findtext() to return empty Unicode string instead of empty bytes object when there's no text.
http://hg.python.org/cpython/rev/849eb27baf1c

New changeset 6323e5f1ed81 by Eli Bendersky in branch '3.3':
Issue #16922: fixed findtext() to return empty Unicode string instead of empty bytes object when there's no text.
http://hg.python.org/cpython/rev/6323e5f1ed81

New changeset c38423931724 by Eli Bendersky in branch 'default':
Issue #16922: fixed findtext() to return empty Unicode string instead of empty bytes object when there's no text.
http://hg.python.org/cpython/rev/c38423931724
History
Date User Action Args
2022-04-11 14:57:40adminsetgithub: 61126
2013-01-13 13:27:38eli.benderskysetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2013-01-13 13:26:58python-devsetnosy: + python-dev
messages: + msg179872
2013-01-13 08:19:06serhiy.storchakasetfiles: + etree_finditer_empty-3.2.patch

messages: + msg179848
2013-01-13 08:18:27serhiy.storchakasetfiles: - etree_finditer_empty-3.2.patch
2013-01-12 22:23:14eli.benderskysetmessages: + msg179836
2013-01-12 16:43:02serhiy.storchakasetfiles: + etree_finditer_empty-3.3.patch

messages: + msg179824
2013-01-12 15:46:49eli.benderskysetmessages: + msg179817
2013-01-12 14:38:11eli.benderskysetmessages: + msg179800
2013-01-12 14:28:50serhiy.storchakasetmessages: + msg179799
2013-01-12 13:58:49eli.benderskysetmessages: + msg179794
2013-01-10 18:14:42serhiy.storchakasetmessages: + msg179581
2013-01-10 18:10:33serhiy.storchakacreate