I'll re-read through `lxml` code but I remember it's done already in `XPathElementEvaluator.__call__` (used in `_Element.xpath()`, via `xpath.xmlXPathEvalExpression`