Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ElementTree.findtext() returns empty bytes object instead of empty string #61126

Closed
serhiy-storchaka opened this issue Jan 10, 2013 · 10 comments
Closed
Labels
topic-XML type-bug An unexpected behavior, bug, or error

Comments

@serhiy-storchaka
Copy link
Member

BPO 16922
Nosy @serhiy-storchaka
Files
  • etree_finditer_empty-3.3.patch
  • etree_finditer_empty-3.2.patch
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2013-01-13.13:27:38.743>
    created_at = <Date 2013-01-10.18:10:33.544>
    labels = ['expert-XML', 'type-bug']
    title = 'ElementTree.findtext() returns empty bytes object instead of empty string'
    updated_at = <Date 2013-01-13.13:27:38.742>
    user = 'https://github.com/serhiy-storchaka'

    bugs.python.org fields:

    activity = <Date 2013-01-13.13:27:38.742>
    actor = 'eli.bendersky'
    assignee = 'none'
    closed = True
    closed_date = <Date 2013-01-13.13:27:38.743>
    closer = 'eli.bendersky'
    components = ['XML']
    creation = <Date 2013-01-10.18:10:33.544>
    creator = 'serhiy.storchaka'
    dependencies = []
    files = ['28708', '28711']
    hgrepos = []
    issue_num = 16922
    keywords = ['patch']
    message_count = 10.0
    messages = ['179580', '179581', '179794', '179799', '179800', '179817', '179824', '179836', '179848', '179872']
    nosy_count = 3.0
    nosy_names = ['eli.bendersky', 'python-dev', 'serhiy.storchaka']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue16922'
    versions = ['Python 3.2', 'Python 3.3', 'Python 3.4']

    @serhiy-storchaka
    Copy link
    Member Author

    >>> import xml.etree.cElementTree as ET
    >>> ET.XML('<root><empty /></root>').findtext('empty')
    b''

    @serhiy-storchaka serhiy-storchaka added topic-XML type-bug An unexpected behavior, bug, or error labels Jan 10, 2013
    @serhiy-storchaka
    Copy link
    Member Author

    I see yet one possible bug, using PyBytes_FromString() in list_join() on 3.2. But I can't demonstrate an example.

    @elibendersky
    Copy link
    Mannequin

    elibendersky mannequin commented Jan 12, 2013

    The fix looks good, but please don't add tests to the doctests - they are deprecated (from 3.3)

    @serhiy-storchaka
    Copy link
    Member Author

    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.

    @elibendersky
    Copy link
    Mannequin

    elibendersky mannequin commented Jan 12, 2013

    Serhiy, indeed - that's issue bpo-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.

    @elibendersky
    Copy link
    Mannequin

    elibendersky mannequin commented Jan 12, 2013

    Tests ported in 3.3 and 3.4

    @serhiy-storchaka
    Copy link
    Member Author

    Here is a patch for 3.3+.

    @elibendersky
    Copy link
    Mannequin

    elibendersky mannequin commented Jan 12, 2013

    PyUnicode_New has been added in 3.3, so the 3.2 patch doesn't compile.

    @serhiy-storchaka
    Copy link
    Member Author

    Indeed. Patch updated.

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Jan 13, 2013

    New changeset 849eb27baf1c by Eli Bendersky in branch '3.2':
    Issue bpo-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 bpo-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 bpo-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

    @elibendersky elibendersky mannequin closed this as completed Jan 13, 2013
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    topic-XML type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant