summaryrefslogtreecommitdiff
path: root/sphinx/util
diff options
context:
space:
mode:
author?ukasz Langa <lukasz@langa.pl>2011-01-08 18:33:29 +0100
committer?ukasz Langa <lukasz@langa.pl>2011-01-08 18:33:29 +0100
commitdb5afa7f0cfb34d04b1dd317596178a3eebc7da2 (patch)
tree16c175e1f9f957085724827f9ba3da63566c14be /sphinx/util
parent79f473f0abe09b6152ce5568f54e0593fca71bbd (diff)
parentda9b53d98d32f118f1239acd52f417c6809d4364 (diff)
downloadsphinx-db5afa7f0cfb34d04b1dd317596178a3eebc7da2.tar.gz
getargspec moved to sphinx.util.inspect
Diffstat (limited to 'sphinx/util')
-rw-r--r--sphinx/util/inspect.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py
index a0574003..c136393f 100644
--- a/sphinx/util/inspect.py
+++ b/sphinx/util/inspect.py
@@ -9,6 +9,40 @@
:license: BSD, see LICENSE for details.
"""
+inspect = __import__('inspect')
+import sys
+
+if sys.version_info >= (2, 5):
+ from functools import partial
+ def getargspec(func):
+ """Like inspect.getargspec but supports functools.partial as well."""
+ if inspect.ismethod(func):
+ func = func.im_func
+ parts = 0, ()
+ if type(func) is partial:
+ parts = len(func.args), func.keywords.keys()
+ func = func.func
+ if not inspect.isfunction(func):
+ raise TypeError('%r is not a Python function' % func)
+ args, varargs, varkw = inspect.getargs(func.func_code)
+ func_defaults = func.func_defaults
+ if func_defaults:
+ func_defaults = list(func_defaults)
+ if parts[0]:
+ args = args[parts[0]:]
+ if parts[1]:
+ for arg in parts[1]:
+ i = args.index(arg) - len(args)
+ del args[i]
+ try:
+ del func_defaults[i]
+ except IndexError:
+ pass
+ return inspect.ArgSpec(args, varargs, varkw, func_defaults)
+else:
+ getargspec = inspect.getargspec
+
+
def isdescriptor(x):
"""Check if the object is some kind of descriptor."""
for item in '__get__', '__set__', '__delete__':