Tomi Belan schrieb am 20.03.25 um 23:53:
You could change .xpath() and etree.XPath() itself so that the expression "string(...)" always returns a plain str. 'Smart' strings will only be returned (as elements of a Python list) when the XPath result is a node set containing text/cdata/attribute nodes. This could be implemented by removing the _elementStringResultFactory() call in _unwrapXPathObject() when xpathObj.type == xpath.XPATH_STRING.
A simple string can still originate from the text content of a single node, in which case we'd want to report the origin by returning a smart string. Distinguishing between "string()" and the text or tail of a node might seem arbitrary and difficult to handle for user code. If users request smart strings, they should get them for all text results and not just for some, with plain string objects mixed in that lack the expected attributes.
Stefan _______________________________________________ lxml - The Python XML Toolkit mailing list -- lxml@python.org To unsubscribe send an email to lxml-le...@python.org https://mail.python.org/mailman3/lists/lxml.python.org/ Member address: arch...@mail-archive.com