【发布时间】:2011-12-13 03:43:27
【问题描述】:
python 的一大优点是能够对方法和函数进行自省。例如,要获取 math.log 的函数签名,您可以(在 ipython 中)运行以下命令:
In [1]: math.log?
Type: builtin_function_or_method
Base Class: <type 'builtin_function_or_method'>
String Form: <built-in function log>
Namespace: Interactive
Docstring:
log(x[, base])
Return the logarithm of x to the given base.
If the base not specified, returns the natural logarithm (base e) of x.
并且看到x 和可选的base 是这个函数的参数。
使用新的 gtk3 和 automaticall generated pygobject bindings,我可以在我尝试的所有示例中只获得 (*args, **kwargs) 作为每个 gtk 方法的参数。
示例:Label.set_text which requires a string:
In [1]: from gi.repository import Gtk
In [2]: mylabel = Gtk.Label("hello")
In [3]: mylabel.set_text?
Type: instancemethod
Base Class: <type 'instancemethod'>
String Form: <bound method Label.set_text of <Label object at 0x275b230 (GtkLabel at 0x28cd040)>>
Namespace: Interactive
File: /usr/lib/python2.7/dist-packages/gi/types.py
Definition: L.set_text(*args, **kwargs)
Docstring:
<no docstring>
现在的问题:这(python 绑定的方法自省的丢失)是否会再次改变(文档)工作已经进入 pygobjects 或者这是由于 pygobjects 的工作方式而保留下来的东西?
【问题讨论】:
-
好问题。我还建议在任何与 pygobject 相关的邮件列表中询问它。
-
自动绑定生成的要点是,通过 gtk-doc 生成的相同 C 文档适用于每种语言。所以,我认为应该有用的是 pygi 的开发人员以与绑定相同的方式为 python 生成文档。
标签: python pygtk pygobject gtk3