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
Add 'sourceline' property to xml.etree Elements #58286
Comments
The lxml implementation of the ElementTree API puts a The attached patch works by copying the current line number from the Expat parser into the Element object after the Element object is created (so as to minimise its intrusiveness for now). The patch is just a proof of concept, and although all tests pass, the patch currently smells a little hacky and fragile to me. Hopefully though, it will start a discussion with somebody more experienced. PS. So as not to create a hard dependency on lxml.etree, in my project I worked around the issue as follows. While this works in my case, the standard library seems a more logical place for this change:: class XMLParserWithLines(XMLParser):
"""
Add a `sourceline` attribute to element, like lxml.etree
"""
def _start_list(self, *args, **kwargs):
element = super(self.__class__, self)._start_list(*args, **kwargs)
element.sourceline = self._parser.CurrentLineNumber
return element
|
Hi Leon, I suggest to start by raising this to the python-ideas mailing list, to see if anyone has objections / different idea about doing this. Next, keep in mind that starting with 3.3, the default ElementTree implementation comes from the C accelerator Modules/_elementtree.c, and compatibility between the Python and C implementations becomes important. Therefore, each such change has to be added to both implementations. Is your patch done in a common section, or just the Python implementation? |
Hi Leon, |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: