[Python-Dev] Should inspect.getargspec take any callable? (original) (raw)
Aviv Cohn avivcohn123 at yahoo.com
Sat Jan 16 11:05:06 EST 2016
- Previous message (by thread): [Python-Dev] 2.7.11 Windows Installer issues on Win2008R2
- Next message (by thread): [Python-Dev] Should inspect.getargspec take any callable?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Hello :)This is my first mail here, I had an idea that I'd like to propose.
The getargspec
function in the inspect
module enforces the input parameter to be either a method or a function.
def getargspec(func): """Get the names and default values of a function's arguments. A tuple of four things is returned: (args, varargs, varkw, defaults). 'args' is a list of the argument names (it may contain nested lists). 'varargs' and 'varkw' are the names of the * and ** arguments or None. 'defaults' is an n-tuple of the default values of the last n arguments. """
if ismethod(func): func = func.im_func if not isfunction(func): raise TypeError('{!r} is not a Python function'.format(func)) args, varargs, varkw = getargs(func.func_code) return ArgSpec(args, varargs, varkw, func.func_defaults)
Passing in a callable which is not a function causes a TypeError to be raised.
I think in this case any callable should be allowed, allowing classes and callable objects as well.We can switch on whether func
is a function, a class or a callable object, and pass into getargs
the appropriate value.
What is your opinion?Thank you
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20160116/134762c6/attachment.html>
- Previous message (by thread): [Python-Dev] 2.7.11 Windows Installer issues on Win2008R2
- Next message (by thread): [Python-Dev] Should inspect.getargspec take any callable?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]