A code illustration as an intro to my questions:
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
It seems that the only way for me to find the signature of datetime.datetime.replace
while I code is to look it up in the doc: date.replace(year, month, day)
.
The only introspection part that seems to work:
datetime.datetime.replace.__doc__
# => 'Return datetime with new specified fields.'
I've examined how the Jupyter function arglist tool-tip works, they have the exact same problem, i.e. no arglist available for datetime.datetime.replace
.
So here are the questions:
Is it still possible to get the argument list somehow? Maybe I could install the C sources for
datetime
and connect them via the__file__
attribute?Is it possible to annotate a
<type 'method_descriptor'>
with the arglist information? In that case, I could parse the linked doc's markdown definition and automatically annotate the built-in module functions.