summaryrefslogtreecommitdiffstats
path: root/Lib/inspect.py
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2003-06-27 18:14:39 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2003-06-27 18:14:39 (GMT)
commit6496788e7a287aedfaa61c0a87feeaeb2fbb06a6 (patch)
tree809cc62bb6a0e673b13a47e8fdb900de7111f7ce /Lib/inspect.py
parent7ff55e6bc548495ea8045194325c0226bf725359 (diff)
downloadcpython-6496788e7a287aedfaa61c0a87feeaeb2fbb06a6.zip
cpython-6496788e7a287aedfaa61c0a87feeaeb2fbb06a6.tar.gz
cpython-6496788e7a287aedfaa61c0a87feeaeb2fbb06a6.tar.bz2
Fix for SF bug 620190: getargspec() doesn't work with methods.
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r--Lib/inspect.py13
1 files changed, 10 insertions, 3 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py
index eca5e8c..4619edb 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -593,7 +593,9 @@ def getargs(co):
Three things are returned: (args, varargs, varkw), where 'args' is
a list of argument names (possibly containing nested lists), and
'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
nargs = co.co_argcount
@@ -642,8 +644,13 @@ def getargspec(func):
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 not isfunction(func): raise TypeError, 'arg is not a Python function'
+ '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('arg is not a Python function')
args, varargs, varkw = getargs(func.func_code)
return args, varargs, varkw, func.func_defaults