You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
xml.etree.cElementTree lacks full dir() on Element #52238
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=<Date2015-11-25.13:30:41.619>created_at=<Date2010-02-22.16:36:02.320>labels= ['extension-modules', 'expert-XML', 'type-feature']
title='xml.etree.cElementTree lacks full dir() on Element'updated_at=<Date2015-11-25.13:30:41.618>user='https://bugs.python.org/ArcRiley'
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.
Following the suggestion, I put "tag", "text", "tail", and "attrib" to be accessible via tp_getset for _etree.Element type.
santosowijaya commented on Apr 14, 2011
santosowijayamannequin
Mannequin
More actions
Is this a right approach? I converted the hard-coded "attributes" into real, C-API attributes.
ArcRiley commented on Apr 14, 2011
ArcRileymannequin
MannequinAuthor
More actions
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.
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"},
Activity
ArcRiley commentedon Feb 22, 2010
The tag property is not listed in dir() making ElementTree more difficult to use for those of us with poor memories.
florentx commentedon 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.
santosowijaya commentedon 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 commentedon Apr 14, 2011
Is this a right approach? I converted the hard-coded "attributes" into real, C-API attributes.
ArcRiley commentedon 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.
elibendersky commentedon 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 commentedon Nov 23, 2015
Here is a patch updated to 3.6.
vadmium commentedon 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 commentedon 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 commentedon Nov 25, 2015
Thank you Martin. Committed with both your suggestions.