holger.jo...@lbbw.de schrieb am 10.09.21 um 16:23:
Then we shouldn't make it one. It's unlikely that data gets passed
through XML in Python syntax. We have the same for "True" and "False",
which come out as str, not bool. And this applies to FloatElement as
well, which uses
float() as parser and thus also supports "_" in Py3.6+.
I'll see what I can come up with.
https://github.com/lxml/lxml/commit/83e6c031994d553b74991501c6cd85e3517fadd
8
Works great! Nice touch with the fuzzy tester ;-).
Some super-simple "benchmarking" indicates there's no noticeable slowdown:
# we're on 4.6.2 so far, haven't bothered to update to latest 4.6.3 release
0 $ (PYTHONPATH=$PYTAF_HOME/2020-Q3-V2/lib/python3.6/site-packages/ python3 -c 'from lxml import etree, objectify;
print(etree.__version__); root =
objectify.XML("<root><x>1000000</x><y>1000_000</y></root>");
print(objectify.dump(root))')
4.6.2
root = None [ObjectifiedElement]
x = 1000000 [IntElement]
y = 1000000 [IntElement]
0 $ (PYTHONPATH=$PYTAF_HOME/2020-Q3-V2/lib/python3.6/site-packages/ python3 -m timeit -r 5 -n 1000000 --setup 'from lxml
import etree, objectify' 'root =
objectify.XML("<root><x>1000000</x><y>1000_000</y></root>")')
1000000 loops, best of 5: 17.5 usec per loop
# current gh version (version number still 4.6.3, from latest release)
0 $ (PYTHONPATH=build/lib.linux-x86_64-3.6/ python3 -c 'from lxml import etree, objectify; print(etree.__version__); root =
objectify.XML("<root><x>1000000</x><y>1000_000</y></root>");
print(objectify.dump(root))')
4.6.3
root = None [ObjectifiedElement]
x = 1000000 [IntElement]
y = '1000_000' [StringElement]
0 $ (PYTHONPATH=build/lib.linux-x86_64-3.6/ python3 -m timeit -r 5 -n 1000000 --setup 'from lxml import etree, objectify'
'root = objectify.XML("<root><x>1000000</x><y>1000_000</y></root>")')
1000000 loops, best of 5: 17.1 usec per loop
(No it's not faster, this is just a lucky timeit run - but it's absolutely in
the same ballpark as before)
… except that this is not a good benchmark – it doesn't call the code that
was changed. :)
You could use `objectify.XML("…").y' to get an actual element tested and
instantiated.
I wouldn't expect much of a difference, though. Parsing will take most of
the time, then actually instantiating the element object. Testing the value
should be quick in comparison (and even quicker now).
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