Julien Palard added the comment:
Hi Serhiy,
> Julien, you can declare the hi parameter as
> hi: Py_ssize_t(py_default="len(a)") = -1
Looks like a good idea, I was aware of its existance but did not took the time
to read the doc about it, kind of learning step by stpe. But as you provided
the syntax, I tested it, thanks for this! But it fails with a RuntimeError
during python -m pydoc _bisect, I'm currently trying to understand why:
$ ./python -m pydoc _bisect
Traceback (most recent call last):
File "/home/mdk/cpython-git/Lib/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "/home/mdk/cpython-git/Lib/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/mdk/cpython-git/Lib/pydoc.py", line 2663, in <module>
cli()
File "/home/mdk/cpython-git/Lib/pydoc.py", line 2628, in cli
help.help(arg)
File "/home/mdk/cpython-git/Lib/pydoc.py", line 1908, in help
elif request: doc(request, 'Help on %s:', output=self._output)
File "/home/mdk/cpython-git/Lib/pydoc.py", line 1645, in doc
pager(render_doc(thing, title, forceload))
File "/home/mdk/cpython-git/Lib/pydoc.py", line 1638, in render_doc
return title % desc + '\n\n' + renderer.document(object, name)
File "/home/mdk/cpython-git/Lib/pydoc.py", line 382, in document
if inspect.ismodule(object): return self.docmodule(*args)
File "/home/mdk/cpython-git/Lib/pydoc.py", line 1172, in docmodule
contents.append(self.document(value, key, name))
File "/home/mdk/cpython-git/Lib/pydoc.py", line 384, in document
if inspect.isroutine(object): return self.docroutine(*args)
File "/home/mdk/cpython-git/Lib/pydoc.py", line 1357, in docroutine
signature = inspect.signature(object)
File "/home/mdk/cpython-git/Lib/inspect.py", line 2994, in signature
return Signature.from_callable(obj, follow_wrapped=follow_wrapped)
File "/home/mdk/cpython-git/Lib/inspect.py", line 2744, in from_callable
follow_wrapper_chains=follow_wrapped)
File "/home/mdk/cpython-git/Lib/inspect.py", line 2223, in
_signature_from_callable
skip_bound_arg=skip_bound_arg)
File "/home/mdk/cpython-git/Lib/inspect.py", line 2055, in
_signature_from_builtin
return _signature_fromstr(cls, func, s, skip_bound_arg)
File "/home/mdk/cpython-git/Lib/inspect.py", line 2003, in _signature_fromstr
p(name, default)
File "/home/mdk/cpython-git/Lib/inspect.py", line 1985, in p
default_node = RewriteSymbolics().visit(default_node)
File "/home/mdk/cpython-git/Lib/ast.py", line 253, in visit
return visitor(node)
File "/home/mdk/cpython-git/Lib/ast.py", line 317, in generic_visit
new_node = self.visit(old_value)
File "/home/mdk/cpython-git/Lib/ast.py", line 253, in visit
return visitor(node)
File "/home/mdk/cpython-git/Lib/inspect.py", line 1977, in visit_Name
return wrap_value(node.id)
File "/home/mdk/cpython-git/Lib/inspect.py", line 1959, in wrap_value
raise RuntimeError()
RuntimeError
> > Curiously, this patch gives about a 10% to 15% speedup. Any sense of how
> > that improvement arises?
> This is rather a random difference. Try to run the bench several times. With
> using Victor's perf module the difference is not significant.
If you search for "perf" in the history of this issue you'll see that I already
tested with Victor's perf module and it yielded a consistent 18% improvement on
bisect.bisect("abcdef", "c") on two different machines. Clearly with more than
5 items, it will start to fade, and with a lot of items, it's not significand,
obviously as it's an optimization about the call and not the implementation. So
Raymond's test with 100 items may still see a speedup.
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue28754>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com