Overriding functions in the default namespace
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
lxml |
Confirmed
|
Low
|
Unassigned | ||
lxml (Ubuntu) |
New
|
Undecided
|
Unassigned |
Bug Description
If I specify a namespace with a prefix, a custom function works fine:
from lxml import etree
_function_ns = etree.FunctionN
_function_ns.prefix = 'a'
def _dummy_count(arg):
return 10
_function_
_xml = etree.Element(
print _xml.xpath(
Output is '10.0'.
But if I add the function to the default namespace, I've got an error:
from lxml import etree
_function_ns = etree.FunctionN
def _dummy_count(arg):
return 10
_function_
_xml = etree.Element(
print _xml.xpath(
Output:
Traceback (most recent call last):
File "/Users/
print _xml.xpath(
File "src/lxml/
File "src/lxml/
File "src/lxml/
lxml.etree.
Seems it doesn't recognise my 'count(arg)' function and use standard 'count(...)' instead.
It works fine with custom functions that are not conflicting with standard functions, but how can I specify a custom function with one of the standard functions name?
---
Python : sys.version_
lxml.etree : (4, 3, 0, 0)
libxml used : (2, 9, 9)
libxml compiled : (2, 9, 9)
libxslt used : (1, 1, 32)
libxslt compiled : (1, 1, 32)
description: | updated |
Hmm, looks like the functions are registered in the wrong order: local first, then global, then EXSLT. Local functions should take precendence. PR welcome, see the _XPathContext class in "xpath.pxi".