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.

classification
Title: documentation of ElementTree.find
Type: behavior Stage: resolved
Components: XML Versions: Python 3.2, Python 3.3, Python 3.4
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: eli.bendersky, flox, patrick.vrijlandt, terry.reedy
Priority: normal Keywords: easy

Created on 2011-06-13 09:49 by patrick.vrijlandt, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (4)
msg138228 - (view) Author: patrick vrijlandt (patrick.vrijlandt) Date: 2011-06-13 09:49
From the python docs for version 3.2:

19.12.3. ElementTree Objects
find(match)
[...] Same as getroot().find(match). [...]

This is not true: tree.find accepts an absolute path (like "/*") , whereas element.find doesn't. Also applies to findall and findtext.
msg138559 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2011-06-17 23:04
Are you requesting that the doc be changed or the code?
From the title, I would infer the doc (which is much easier ;-).
If so, can you suggest an actual revised text?
msg138653 - (view) Author: patrick vrijlandt (patrick.vrijlandt) Date: 2011-06-19 18:16
[...] Same as getroot().find(match). [...] ->
[...] For a relative path, this is equivalent to getroot().find(match).
Additionally, this form accepts an absolute path. [...]

This is easy, but might not be a very good solution.

Random thoughts/Points to consider:
It does help the novice in debugging his expressions.
A peculiarity of this implementation is documented.
As others have stated, the whole elementpath documentation within the python
docs is incomplete. Should we document the exception but not the rule?
It makes no real sense to do a an absolute search from an element. However,
it's not ambiguous.
lxml does accept the absolute path search from an element.

Actually, I think it's up to Fredrik to decide.

2011/6/18 Terry J. Reedy <report@bugs.python.org>

>
> Terry J. Reedy <tjreedy@udel.edu> added the comment:
>
> Are you requesting that the doc be changed or the code?
> >From the title, I would infer the doc (which is much easier ;-).
> If so, can you suggest an actual revised text?
>
> ----------
> nosy: +terry.reedy
> stage:  -> needs patch
> versions: +Python 3.3
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue12321>
> _______________________________________
>
msg172881 - (view) Author: Eli Bendersky (eli.bendersky) * (Python committer) Date: 2012-10-14 13:30
I think this may be intentional. Absolute searches on a ElementTree are discouraged with a warning:

    def find(self, path, namespaces=None):
        # assert self._root is not None
        if path[:1] == "/":
            path = "." + path
            warnings.warn(
                "This search is broken in 1.3 and earlier, and will be "
                "fixed in a future version.  If you rely on the current "
                "behaviour, change it to %r" % path,
                FutureWarning, stacklevel=2
                )
        return self._root.find(path, namespaces)

See what happens when an "absolute path" is attemped? The code just hacks it into a relative path and prints a menacing warning.

So, I would not change the documentation at this point. However, the problem should go away if and when the XPath support is improved to really support absolute paths.
History
Date User Action Args
2022-04-11 14:57:18adminsetgithub: 56530
2012-10-14 13:30:51eli.benderskysetstatus: open -> closed
resolution: wont fix
messages: + msg172881

stage: needs patch -> resolved
2012-10-14 13:19:47eli.benderskysetversions: + Python 3.4
2012-10-14 13:19:39eli.benderskysetfiles: - unnamed
2012-09-15 23:29:51ezio.melottisetkeywords: + easy
2012-07-21 14:11:47floxsetnosy: + eli.bendersky
2011-06-19 18:16:17patrick.vrijlandtsetfiles: + unnamed

messages: + msg138653
2011-06-17 23:04:20terry.reedysetversions: + Python 3.3
nosy: + terry.reedy

messages: + msg138559

stage: needs patch
2011-06-13 12:59:21pitrousetnosy: + flox
2011-06-13 09:49:21patrick.vrijlandtcreate