lxml.etree._ElementTree.find() fails on objectify.parse result

Bug #850670 reported by Andrey Rahmatullin
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
lxml
Fix Released
Medium
scoder

Bug Description

If a tree was created by objectify.parse, I can't use find() on it, I need to use getroot().find():

>>> from lxml import objectify
>>> from StringIO import StringIO
>>> f = StringIO("<root>data</root>")
>>> tree = objectify.parse(f)
>>> tree.find.__doc__.split('\n')[0]
'find(self, path, namespaces=None)'
>>> tree.find('/root')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "lxml.etree.pyx", line 1944, in lxml.etree._ElementTree.find (src/lxml/lxml.etree.c:45105)
TypeError: find() takes exactly one argument (2 given)
>>> tree.getroot().find.__doc__
'find(self, path)'
>>> tree.getroot().find('/root')
<Element root at 0x7f1655843a50>
>>> tree.getroot().find('/root', None)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: find() takes exactly one argument (2 given)

This testcase is also attached.

Here tree.find('/root') actually translates to tree.getroot().find('/root', None), and apparently tree.getroot().find in the objectify case doesn't take the namespaces argument (it also looks like a dynamically created function). Note that if the tree was created by etree.parse, the code doesn't fail, because in this case tree.getroot().find has the same signature (and proper verbose docstring) as tree.find.

Python : (2, 6, 7, 'final', 0)
lxml.etree : (2, 3, 0, 0)
libxml used : (2, 7, 8)
libxml compiled : (2, 7, 8)
libxslt used : (1, 1, 26)
libxslt compiled : (1, 1, 26)

Revision history for this message
Andrey Rahmatullin (wrar) wrote :
Revision history for this message
scoder (scoder) wrote :

Hmm, right - I guess ObjectifiedElement.find*() would better use ObjectPath expressions than ElementPath.

Changed in lxml:
importance: Undecided → Medium
status: New → Confirmed
Revision history for this message
scoder (scoder) wrote :

Actually, I switched these methods to use the implementation from lxml.etree now. I think that's more consistent and also fixes some behavioural quirks. It's also faster in many cases.

Changed in lxml:
assignee: nobody → Stefan Behnel (scoder)
milestone: none → 2.4
status: Confirmed → Fix Committed
Revision history for this message
scoder (scoder) wrote :

Fixed in lxml 3.0 alpha 1.

Changed in lxml:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.