This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2012年02月21日 22:25 by leonov, last changed 2022年04月11日 14:57 by admin. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| elementtree-sourceline.diff | leonov, 2012年02月21日 22:25 | Initial, proof of concept patch | review | |
| Messages (3) | |||
|---|---|---|---|
| msg153907 - (view) | Author: Leon Matthews (leonov) | Date: 2012年02月21日 22:25 | |
The lxml implementation of the ElementTree API puts a `sourceline` property onto every Element object, which I recently found useful when producing diagnostic messages. I think it would be a useful improvement to make the standard library's ElementTree implementation. 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 >>> tree = ElementTree() >>> tree.parse(path, parser=XMLParserWithLines()) >>> ... |
|||
| msg156558 - (view) | Author: Eli Bendersky (eli.bendersky) * (Python committer) | Date: 2012年03月22日 13:34 | |
Hi Leon, Thanks for the patch. 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? |
|||
| msg161761 - (view) | Author: Eli Bendersky (eli.bendersky) * (Python committer) | Date: 2012年05月28日 08:31 | |
Hi Leon, Do you have an interest in pursuing this issue? |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:57:27 | admin | set | github: 58286 |
| 2012年06月08日 12:32:29 | eli.bendersky | set | status: open -> closed resolution: wont fix stage: patch review -> resolved |
| 2012年05月28日 08:31:50 | eli.bendersky | set | messages: + msg161761 |
| 2012年03月22日 13:34:51 | eli.bendersky | set | messages: + msg156558 |
| 2012年03月22日 12:29:46 | r.david.murray | set | keywords:
+ needs review type: enhancement stage: patch review |
| 2012年03月21日 19:16:42 | ned.deily | set | nosy:
+ eli.bendersky |
| 2012年02月21日 22:25:31 | leonov | create | |