A碼圖作爲介紹到我的問題:Python內省:獲取method_descriptor的參數列表?
import re, inspect, datetime
inspect.getargspec (re.findall)
# =>
# ArgSpec(args = ['pattern', 'string', 'flags'], varargs=None,
# keywords=None, defaults = (0,))
type (datetime.datetime.replace)
# => <type 'method_descriptor'>
inspect.getargspec (datetime.datetime.replace)
# => Traceback (most recent call last):
# File "<stdin>", line 1, in <module>
# File "/usr/lib/python2.7/inspect.py", line 816, in getargspec
# raise TypeError('{!r} is not a Python function'.format(func))
# TypeError: <method 'replace' of 'datetime.datetime' objects> is
# not a Python function
看來,我唯一的方式找到的datetime.datetime.replace
簽名,而我的代碼是看它在the doc:date.replace(year, month, day)
。
唯一的內省部分:
datetime.datetime.replace.__doc__
# => 'Return datetime with new specified fields.'
我已經檢查了Jupyter功能的arglist工具提示是如何工作的,他們有相同的問題,即沒有可用於datetime.datetime.replace
arglist中。
所以這裏的問題:
是否仍然有可能以某種方式獲取參數列表?也許我可以安裝
datetime
的C源代碼並通過__file__
屬性連接它們?是否可以使用arglist信息註釋
<type 'method_descriptor'>
?在這種情況下,我可以解析鏈接文檔的降價定義並自動註釋內置的模塊功能。