-
-
Notifications
You must be signed in to change notification settings - Fork 33.6k
gh-140123: Make ElementTree.find use registered global namespaces #140364
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
base: main
Are you sure you want to change the base?
gh-140123: Make ElementTree.find use registered global namespaces #140364
Conversation
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
ElementTree.find, findall, findtext, and iterfind now use the global _namespace_map as fallback when no namespaces argument is provided. Fixes inconsistencies between ElementTree and ElementPath when using ET.register_namespace.
…izer (pythonGH-140123) The namespace prefix resolution in ElementPath.xpath_tokenizer now properly uses globally registered namespaces after trying local namespaces first. This ensures consistent namespace handling across both Python and C implementations.
- Remove duplicate import of xml.etree.ElementTree as ET - Add missing newline at end of NEWS entry file
ElementTree.find, findall, findtext, and iterfind now use the global _namespace_map as fallback when no namespaces argument is provided. Fixes inconsistencies between ElementTree and ElementPath when using ET.register_namespace.
…izer (pythonGH-140123) The namespace prefix resolution in ElementPath.xpath_tokenizer now properly uses globally registered namespaces after trying local namespaces first. This ensures consistent namespace handling across both Python and C implementations.
- Remove duplicate import of xml.etree.ElementTree as ET - Add missing newline at end of NEWS entry file
18a22ac to
8c6a6e4
Compare
Fix issue where self.parser was incorrectly initialized in XMLParser.__init__. The parser was being created twice and the wrong instance was being assigned. Now both self.parser and self._parser point to the same parser instance, maintaining backward compatibility and fixing the AttributeError in tests.
|
Can I ask why I was added as a reviewer to this PR, @sangampaudel530 ? |
|
I think it was an automatic CODEOWNER request due to a bad merge commit (https://github.com/python/cpython/commits/18a22ac9ca08fe8935768c4cc8e22dc141d52c9b), subsequently overwritten by force push. A |
ElementTree.find, findall, findtext, and iterfind now use the global _namespace_map as fallback when no namespaces argument is provided. This fixes inconsistencies between ElementTree and ElementPath when using ET.register_namespace.
Example usage:
import xml.etree.ElementTree as ET
ET.register_namespace('h', 'http://www.w3.org/TR/html4/')
tree = ET.parse('xml/example.xml')
tree.find('.//h:title') # now works without manually passing namespaces