[issue13784] Documentation of xml.sax.xmlreader: Locator.getLineNumber() and Locator.getColumnNumber()
New submission from patrick vrijlandt <patrick.vrijlandt@gmail.com>: Problem: Locator methods return the location where the event starts, not where it ends. Locator line numbers start at 1, Locator column numbers can be 0. Proposal: Adapt documentation.
From the docs: Instances of Locator provide these methods:
Locator.getColumnNumber() Return the column number where the current event ends. Locator.getLineNumber() Return the line number where the current event ends My Test: import xml.sax data = b"""<main> <sub attr="1" id="name" > <subsub /> </sub> </main>""" class MyHandler(xml.sax.handler.ContentHandler): def startElement(self, name, attrs): if name == "sub": print("open", name, self._locator.getLineNumber(), self._locator.getColumnNumber()) def endElement(self, name): if name == "sub": print("close", name, self._locator.getLineNumber(), self._locator.getColumnNumber()) xml.sax.parseString(data, MyHandler()) Output: open sub 2 4 close sub 7 4 ---------- assignee: docs@python components: Documentation, XML messages: 151247 nosy: docs@python, patrick.vrijlandt priority: normal severity: normal status: open title: Documentation of xml.sax.xmlreader: Locator.getLineNumber() and Locator.getColumnNumber() type: behavior versions: Python 3.2 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13784> _______________________________________
Mark Lawrence added the comment: @patrick please accept our apologies for the delay in getting back to you. ---------- nosy: +BreamoreBoy, christian.heimes versions: +Python 3.4, Python 3.5 -Python 3.2 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13784> _______________________________________
Emily Morehouse added the comment: The reported behavior has been verified -- the documented behavior is indeed incorrect for both Locator.getColumnNumber() and Locator.getLineNumber(). The beginning line and column numbers are returned, not the end. This has been tested and verified for Python 2.7, Python 3.5.1 and a local build of the current default branch. ---------- keywords: +patch nosy: +emilyemorehouse versions: +Python 2.7, Python 3.2, Python 3.3, Python 3.6 Added file: http://bugs.python.org/file43109/13784.patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13784> _______________________________________
R. David Murray added the comment: Thanks Emily. For some reason the auto update of the tracker doesn't seem to have worked. Maybe it is just delayed, but in case, the commit hashes are 2.7 97b76fe183f4, 3.5 9d6a9e2ae18b, and 3.6 cce04851d2e2. ---------- nosy: +r.david.murray resolution: -> fixed stage: -> resolved status: open -> closed versions: -Python 3.2, Python 3.3, Python 3.4 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13784> _______________________________________
Roundup Robot added the comment: New changeset 97b76fe183f4 by R David Murray in branch '2.7': #13784: fix xml.sax.reader getColumn/LineNumber docs. https://hg.python.org/cpython/rev/97b76fe183f4 New changeset 9d6a9e2ae18b by R David Murray in branch '3.5': #13784: fix xml.sax.reader getColumn/LineNumber docs. https://hg.python.org/cpython/rev/9d6a9e2ae18b New changeset cce04851d2e2 by R David Murray in branch 'default': Merge: #13784: fix xml.sax.reader getColumn/LineNumber docs. https://hg.python.org/cpython/rev/cce04851d2e2 ---------- nosy: +python-dev _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue13784> _______________________________________
participants (5)
-
Emily Morehouse
-
Mark Lawrence
-
patrick vrijlandt
-
R. David Murray
-
Roundup Robot