CPython 扩展的基于关键字的文档
Keyword-based documentation for CPython extensions
应该如何编写 CPython 扩展以便 pydoc
提及参数名称而不是 (...)
?
我遵循了 official python tutorial about extending Python,甚至对于 keywdarg.parrot
程序,我得到:
$> pydoc kewdarg.parrot
parrot(...)
Print a lovely skit to standard output.
而我希望
parrot(voltage, state="a stiff", action="voom", type="Norwegian Blue")
Print a lovely skit to standard output.
查看 sources of pydoc,如果我没记错的话,产生“...”的节是:
if inspect.isfunction(object):
args, varargs, varkw, defaults = inspect.getargspec(object)
argspec = inspect.formatargspec(
args, varargs, varkw, defaults, formatvalue=self.formatvalue)
if realname == '<lambda>':
title = '<strong>%s</strong> <em>lambda</em> ' % name
argspec = argspec[1:-1] # remove parentheses
else:
argspec = '(...)'
因此,在 CPython 扩展的情况下,inspect.isfunction(object)
是 returning False。
由于 inspect.isfunction() 检查对象是 Python 函数 ,而 C 扩展函数被认为是 builtins,那么以上将 return False 并且我们在输出中得到 (...)
.
应该如何编写 CPython 扩展以便 pydoc
提及参数名称而不是 (...)
?
我遵循了 official python tutorial about extending Python,甚至对于 keywdarg.parrot
程序,我得到:
$> pydoc kewdarg.parrot
parrot(...)
Print a lovely skit to standard output.
而我希望
parrot(voltage, state="a stiff", action="voom", type="Norwegian Blue")
Print a lovely skit to standard output.
查看 sources of pydoc,如果我没记错的话,产生“...”的节是:
if inspect.isfunction(object):
args, varargs, varkw, defaults = inspect.getargspec(object)
argspec = inspect.formatargspec(
args, varargs, varkw, defaults, formatvalue=self.formatvalue)
if realname == '<lambda>':
title = '<strong>%s</strong> <em>lambda</em> ' % name
argspec = argspec[1:-1] # remove parentheses
else:
argspec = '(...)'
因此,在 CPython 扩展的情况下,inspect.isfunction(object)
是 returning False。
由于 inspect.isfunction() 检查对象是 Python 函数 ,而 C 扩展函数被认为是 builtins,那么以上将 return False 并且我们在输出中得到 (...)
.