-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
bpo-31648: Improve ElementPath #3835
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
Conversation
…he current node, like "[.='text']".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a What's New entry. Document the new feature and add a "versionchanged" directive in the documentation.
@@ -0,0 +1,3 @@ | |||
Improvements to path predicates in ElementTree: | |||
* Allow whitespace around predicate parts, i.e. "[a = 'text']" instead of requiring the less readable "[a='text']". | |||
* Add support for text comparison of the current node, like "[.='text']". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add "Patch by Stefan Behnel".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
['section']) | ||
self.assertEqual(summarize_list(e.findall(".//section[tag = 'subtext']")), | ||
['section']) | ||
self.assertEqual(summarize_list(e.findall(".//section[ tag = 'subtext' ]")), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't be enough to test just this variant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whitebox testing, yes. Blackbox testing, no. It's short enough, so I chose the latter. In parsers, it's easy to accidentally forget about special cases.
['tag']) | ||
self.assertEqual(summarize_list(e.findall('.//tag[.= "subtext"]')), | ||
['tag']) | ||
self.assertEqual(summarize_list(e.findall('.//tag[ . = "subtext" ]')), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't be enough to test just this variant?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment applies.
Lib/xml/etree/ElementPath.py
Outdated
else: | ||
def select(context, result): | ||
for elem in result: | ||
if "".join(elem.itertext()) == value: | ||
yield elem | ||
break |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there shouldn't be a break
. Add a test for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is inside of a predicate, so we only care about "found" or "not found". The break was there before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The break was there before for breaking an internal loop. findall()
should find all elements, not the first one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, you're right. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
Documentation updated. |
Doc/whatsnew/3.7.rst
Outdated
ElementPath predicates in the :meth:`find` methods can now compare text | ||
of the current node with ``[. = "text"]``, not only text in children. | ||
Predicates also allow adding spaces for better readability. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add "(Contributed by ...)" as in other entries.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -157,6 +157,8 @@ def prepare_predicate(next, token): | |||
return | |||
if token[0] == "]": | |||
break | |||
if token == ('', ''): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it for whitespaces? Please add a comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
yield elem | ||
break |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a special test case for this bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, it is already added!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already done.
Doc/whatsnew/3.7.rst
Outdated
ElementPath predicates in the :meth:`find` methods can now compare text | ||
of the current node with ``[. = "text"]``, not only text in children. | ||
Predicates also allow adding spaces for better readability. | ||
(Contributed by Stefan Behnel.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a reference to the issue.
@@ -0,0 +1,4 @@ | |||
Improvements to path predicates in ElementTree: | |||
* Allow whitespace around predicate parts, i.e. "[a = 'text']" instead of requiring the less readable "[a='text']". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These lines are merged together in the generated HTML. Add empty lines before and after the enumeration list.
Updated. |
* Allow whitespace around predicate parts, i.e. "[a = 'text']" instead of requiring the less readable "[a='text']". | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this one is redundant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed.
Doc/whatsnew/3.7.rst
Outdated
xml.etree | ||
--------- | ||
|
||
ElementPath predicates in the :meth:`find` methods can now compare text |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make ElementPath
a link:
:class:`~xml.etree.ElementPath`
Add a reference to elementtree-xpath
:
:ref:`some text <elementtree-xpath>`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a reference.
Updated the news entries. |
https://bugs.python.org/issue31648