You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"inspect.getargspec()" and "inspect.getcallargs()" don't work for builtins #60694
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee='https://github.com/larryhastings'closed_at=<Date2014-01-27.20:34:56.195>created_at=<Date2012-11-17.03:36:29.421>labels= ['type-feature']
title='"inspect.getargspec()" and "inspect.getcallargs()" don\'t work for builtins'updated_at=<Date2014-01-27.20:34:56.194>user='https://github.com/jcea'
Yesterday I was attending a conference about a MOCK like library and the speaker told us about some "inspect" functionalities not working correctly with builtins. For instance:
"""
Python 3.3.0 (default, Oct 2 2012, 02:07:16)
[GCC 4.4.3] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import inspect
>>> deff(a=None) :
... pass
...
>>> inspect.getcallargs(f)
{'a': None}
>>> inspect.getargspec(f)
ArgSpec(args=['a'], varargs=None, keywords=None, defaults=(None,))
>>> inspect.getcallargs(list)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.3/inspect.py", line 993, in getcallargs
spec = getfullargspec(func)
File "/usr/local/lib/python3.3/inspect.py", line 850, in getfullargspec
raise TypeError('{!r} is not a Python function'.format(func))
TypeError: <class 'list'> is not a Python function
>>> inspect.getargspec(list)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python3.3/inspect.py", line 823, in getargspec
getfullargspec(func)
File "/usr/local/lib/python3.3/inspect.py", line 850, in getfullargspec
raise TypeError('{!r} is not a Python function'.format(func))
TypeError: <class 'list'> is not a Python function
>>>
"""
Can we annotate builtins to support this?. What about types defined in CModules?
changed the title [-]"inspect.getargspec()" and "inspect.getcallargs()" don't work with builtins[/-][+]"inspect.getargspec()" and "inspect.getcallargs()" don't work for builtins[/+]on Nov 17, 2012
I am fully aware that the interpreter doesn't know how a method/function written in C is going to parse the parameter list/keywords. And that even if we solve this (for instance, with annotations that create wrappers calling "PyArg_Parse()" automatically), every C extension out there would need to support it too.
So at this point you should use inspect.signature(), not getfullargspec().
With that you could do this if you either allowed setting the __signature__ attribute and then provided code that would set it, made __signature__ a property that returned the Signature object if desired on a built-in, or come up with some automated way to take the argument string from PyArg_Parse() as you suggested.
Activity
jcea commentedon Nov 17, 2012
Yesterday I was attending a conference about a MOCK like library and the speaker told us about some "inspect" functionalities not working correctly with builtins. For instance:
Can we annotate builtins to support this?. What about types defined in CModules?
[-]"inspect.getargspec()" and "inspect.getcallargs()" don't work with builtins[/-][+]"inspect.getargspec()" and "inspect.getcallargs()" don't work for builtins[/+]jcea commentedon Nov 17, 2012
I am fully aware that the interpreter doesn't know how a method/function written in C is going to parse the parameter list/keywords. And that even if we solve this (for instance, with annotations that create wrappers calling "PyArg_Parse()" automatically), every C extension out there would need to support it too.
Just brainstorming.
brettcannon commentedon Nov 17, 2012
So at this point you should use inspect.signature(), not getfullargspec().
With that you could do this if you either allowed setting the __signature__ attribute and then provided code that would set it, made __signature__ a property that returned the Signature object if desired on a built-in, or come up with some automated way to take the argument string from PyArg_Parse() as you suggested.
larryhastings commentedon Nov 17, 2012
I'm working on a solution for this--expect an announcement on c.l.p-d in, oh, a week.
jcea commentedon Nov 30, 2012
Larry, Ping... :-)
larryhastings commentedon Dec 3, 2012
http://mail.python.org/pipermail/python-dev/2012-December/122920.html
davidvilla commentedon Dec 4, 2012
What about something like gobject.introspection?
https://live.gnome.org/GObjectIntrospection/
jcea commentedon Dec 6, 2012
David, please subscribe to Issue bpo-16612.
berkerpeksag commentedon Dec 9, 2012
This looks like a duplicate of bpo-1748064.
1st1 commentedon Jan 11, 2014
This is related to issue bpo-17481
1st1 commentedon Jan 27, 2014
Closing this issue. See bpo-17481 for details.