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

xml.etree.cElementTree lacks full dir() on Element #52238

Closed
ArcRiley mannequin opened this issue Feb 22, 2010 · 10 comments
Closed

xml.etree.cElementTree lacks full dir() on Element #52238

ArcRiley mannequin opened this issue Feb 22, 2010 · 10 comments
Assignees
Labels
extension-modules C modules in the Modules dir topic-XML type-feature A feature request or enhancement

Comments

@ArcRiley
Copy link
Mannequin

ArcRiley mannequin commented Feb 22, 2010

BPO 7990
Nosy @tiran, @florentx, @vadmium, @serhiy-storchaka
Dependencies
  • bpo-6472: Update ElementTree with upstream changes
  • Files
  • dir_elem_c.patch
  • etree_attributes.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 = 'https://github.com/serhiy-storchaka'
    closed_at = <Date 2015-11-25.13:30:41.619>
    created_at = <Date 2010-02-22.16:36:02.320>
    labels = ['extension-modules', 'expert-XML', 'type-feature']
    title = 'xml.etree.cElementTree lacks full dir() on Element'
    updated_at = <Date 2015-11-25.13:30:41.618>
    user = 'https://bugs.python.org/ArcRiley'

    bugs.python.org fields:

    activity = <Date 2015-11-25.13:30:41.618>
    actor = 'serhiy.storchaka'
    assignee = 'serhiy.storchaka'
    closed = True
    closed_date = <Date 2015-11-25.13:30:41.619>
    closer = 'serhiy.storchaka'
    components = ['Extension Modules', 'XML']
    creation = <Date 2010-02-22.16:36:02.320>
    creator = 'ArcRiley'
    dependencies = ['6472']
    files = ['21041', '41133']
    hgrepos = []
    issue_num = 7990
    keywords = ['patch']
    message_count = 10.0
    messages = ['99777', '99929', '130306', '133747', '133751', '194315', '255143', '255245', '255344', '255346']
    nosy_count = 9.0
    nosy_names = ['effbot', 'christian.heimes', 'eli.bendersky', 'ArcRiley', 'flox', 'santoso.wijaya', 'python-dev', 'martin.panter', 'serhiy.storchaka']
    pr_nums = []
    priority = 'low'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue7990'
    versions = ['Python 3.6']

    @ArcRiley
    Copy link
    Mannequin Author

    ArcRiley mannequin commented Feb 22, 2010

    >>> import xml.etree.cElementTree as ET
    >>> tree = ET.parse('test.xml')
    >>> root = tree.getroot()
    >>> dir(root)
    ['!__reduce__', '__class__', '__copy__', '__deepcopy__', '__delattr__', '__delitem__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__gt__', '__hash__', '__init__', '__le__', '__len__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setitem__', '__sizeof__', '__str__', '__subclasshook__', 'append', 'clear', 'find', 'findall', 'findtext', 'get', 'getchildren', 'getiterator', 'insert', 'items', 'keys', 'makeelement', 'remove', 'set']
    >>> root.tag
    '{http://testnamespace}root'

    The tag property is not listed in dir() making ElementTree more difficult to use for those of us with poor memories.

    @ArcRiley ArcRiley mannequin added the type-bug An unexpected behavior, bug, or error label Feb 22, 2010
    @florentx
    Copy link
    Mannequin

    florentx mannequin commented Feb 23, 2010

    Confirmed.

    As a workaround, the Python implementation shows its attributes "tag", "text", "tail", "attrib".

    Since upstream version of ElementTree drops support for Python < 2.3, we may refactor the Element type, and use the "tp_members" and "tp_getset" slots.

    @florentx florentx mannequin added extension-modules C modules in the Modules dir topic-XML labels Feb 23, 2010
    @florentx florentx mannequin assigned effbot Feb 23, 2010
    @florentx florentx mannequin added type-feature A feature request or enhancement and removed type-bug An unexpected behavior, bug, or error labels Feb 23, 2010
    @santosowijaya
    Copy link
    Mannequin

    santosowijaya mannequin commented Mar 8, 2011

    Attached a patch with test for this:

    Following the suggestion, I put "tag", "text", "tail", and "attrib" to be accessible via tp_getset for _etree.Element type.

    @santosowijaya
    Copy link
    Mannequin

    santosowijaya mannequin commented Apr 14, 2011

    Is this a right approach? I converted the hard-coded "attributes" into real, C-API attributes.

    @ArcRiley
    Copy link
    Mannequin Author

    ArcRiley mannequin commented Apr 14, 2011

    It looks right to me, but I would include more verbose pydoc strings.

    IE, "The tail attribute can be used to hold additional data associated with the element" tells me nothing. You could explain here what .tail actually is, a few XML examples of what would be put in tail or what tail would become, and the API design reason why tail is used in addition to text.

    @florentx florentx mannequin unassigned effbot Jul 21, 2012
    @elibendersky
    Copy link
    Mannequin

    elibendersky mannequin commented Aug 3, 2013

    Could you please refresh the patch for Python 3.3 and 3.4 (_elementtree went through many changes in 3.3)?

    @serhiy-storchaka
    Copy link
    Member

    Here is a patch updated to 3.6.

    @serhiy-storchaka serhiy-storchaka self-assigned this Nov 23, 2015
    @vadmium
    Copy link
    Member

    vadmium commented Nov 24, 2015

    The patch looks technically good, though I’m not a big fan of the double underscores, like element_get__text(). Maybe element_text_getter() instead, because it has to match the “getter” signature?

    Personally, I would say keep the doc strings basic. If you want to add more depth about “tail”, I suggest to keep it to the main RST documentation (which was updated fairly recently). But it would be good to quickly distinguish text and tail other than by name. Maybe:

    {"text", ..., "A string of text directly after the start tag, or None"},
    {"tail", ..., "A string of text directly after the end tag, or None"},

    @python-dev
    Copy link
    Mannequin

    python-dev mannequin commented Nov 25, 2015

    New changeset fef7f041c1a7 by Serhiy Storchaka in branch 'default':
    Issue bpo-7990: dir() on ElementTree.Element now lists properties: "tag",
    https://hg.python.org/cpython/rev/fef7f041c1a7

    @serhiy-storchaka
    Copy link
    Member

    Thank you Martin. Committed with both your suggestions.

    @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
    extension-modules C modules in the Modules dir topic-XML type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants