-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
bpo-40624: Add support for the XPath != operator in xml.etree #22147
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
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.
That's a pretty good start. Some comments below.
Lib/xml/etree/ElementPath.py
Outdated
matches = elem.get(key) == value | ||
if negate_predicate: | ||
matches = not matches |
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 doesn't look correct. If the element does not have such an attribute, .get()
will return None
, which probably does not compare equal to value
. Negating that gives True
. However, @attr != "value"
should only match if there is an attribute attr
that compares unequal.
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.
Aah good catch, thank you! Fixed.
Lib/xml/etree/ElementPath.py
Outdated
negate_predicate = '!' in signature | ||
def select(context, result): |
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 use separate functions for performance reasons. They are deeply nested and a single instruction less can make a visible difference on large enough data. This implementation probably adds 4 byte code instructions to the inner loop.
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.
Gotcha, added a separate function for the negated conditions.
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.
Needs changes.
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 |
dc8efc1
to
9029602
Compare
I have made the requested changes; please review again Also added documentation that I realized I missed. |
Thanks for making the requested changes! @scoder: please review the changes made to this pull request. |
Test failure looks unrelated. |
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.
Looks good now. A few more suggestions.
Co-authored-by: scoder <[email protected]>
Thanks! |
Fairly simple implementation that uses the existing code for
=
and negates the condition if it's a!=
.https://bugs.python.org/issue40624