summaryrefslogtreecommitdiff
path: root/Lib/inspect.py
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@sprymix.com>2016-01-11 15:15:01 -0500
committerYury Selivanov <yselivanov@sprymix.com>2016-01-11 15:15:01 -0500
commit37dc2b28834c95d24746c2958e9ea31d3e8d1968 (patch)
tree86745aeede3b7ebc00dbde82ffb0cc8d8ffae2dc /Lib/inspect.py
parentec71f1779fc4d3509e8f16197a99a6ed3706a591 (diff)
downloadcpython-git-37dc2b28834c95d24746c2958e9ea31d3e8d1968.tar.gz
Issue #25486: Resurrect inspect.getargspec in 3.6. Backout a565aad5d6e1.
The decision is that we shouldn't remove popular APIs (however long they are depreacted) from Python 3, while 2.7 is still around and supported.
Diffstat (limited to 'Lib/inspect.py')
-rw-r--r--Lib/inspect.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/inspect.py b/Lib/inspect.py
index 7615e5277f..74f3b3c3bb 100644
--- a/Lib/inspect.py
+++ b/Lib/inspect.py
@@ -1004,6 +1004,31 @@ def _getfullargs(co):
varkw = co.co_varnames[nargs]
return args, varargs, kwonlyargs, varkw
+
+ArgSpec = namedtuple('ArgSpec', 'args varargs keywords defaults')
+
+def getargspec(func):
+ """Get the names and default values of a function's arguments.
+
+ A tuple of four things is returned: (args, varargs, keywords, defaults).
+ 'args' is a list of the argument names, including keyword-only argument names.
+ 'varargs' and 'keywords' are the names of the * and ** arguments or None.
+ 'defaults' is an n-tuple of the default values of the last n arguments.
+
+ Use the getfullargspec() API for Python 3 code, as annotations
+ and keyword arguments are supported. getargspec() will raise ValueError
+ if the func has either annotations or keyword arguments.
+ """
+ warnings.warn("inspect.getargspec() is deprecated, "
+ "use inspect.signature() instead", DeprecationWarning,
+ stacklevel=2)
+ args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, ann = \
+ getfullargspec(func)
+ if kwonlyargs or ann:
+ raise ValueError("Function has keyword-only arguments or annotations"
+ ", use getfullargspec() API which can support them")
+ return ArgSpec(args, varargs, varkw, defaults)
+
FullArgSpec = namedtuple('FullArgSpec',
'args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, annotations')