mirror of
https://github.com/python/cpython.git
synced 2025-09-21 16:10:33 +00:00
Fix for SF bug 620190: getargspec() doesn't work with methods.
This commit is contained in:
parent
7ff55e6bc5
commit
6496788e7a
1 changed files with 10 additions and 3 deletions
|
@ -593,7 +593,9 @@ def getargs(co):
|
||||||
Three things are returned: (args, varargs, varkw), where 'args' is
|
Three things are returned: (args, varargs, varkw), where 'args' is
|
||||||
a list of argument names (possibly containing nested lists), and
|
a list of argument names (possibly containing nested lists), and
|
||||||
'varargs' and 'varkw' are the names of the * and ** arguments or None."""
|
'varargs' and 'varkw' are the names of the * and ** arguments or None."""
|
||||||
if not iscode(co): raise TypeError, 'arg is not a code object'
|
|
||||||
|
if not iscode(co):
|
||||||
|
raise TypeError('arg is not a code object')
|
||||||
|
|
||||||
code = co.co_code
|
code = co.co_code
|
||||||
nargs = co.co_argcount
|
nargs = co.co_argcount
|
||||||
|
@ -642,8 +644,13 @@ def getargspec(func):
|
||||||
A tuple of four things is returned: (args, varargs, varkw, defaults).
|
A tuple of four things is returned: (args, varargs, varkw, defaults).
|
||||||
'args' is a list of the argument names (it may contain nested lists).
|
'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.
|
'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."""
|
'defaults' is an n-tuple of the default values of the last n arguments.
|
||||||
if not isfunction(func): raise TypeError, 'arg is not a Python function'
|
"""
|
||||||
|
|
||||||
|
if ismethod(func):
|
||||||
|
func = func.im_func
|
||||||
|
if not isfunction(func):
|
||||||
|
raise TypeError('arg is not a Python function')
|
||||||
args, varargs, varkw = getargs(func.func_code)
|
args, varargs, varkw = getargs(func.func_code)
|
||||||
return args, varargs, varkw, func.func_defaults
|
return args, varargs, varkw, func.func_defaults
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue