summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichele Simionato <michele.simionato@gmail.com>2018-04-15 10:22:21 +0200
committerMichele Simionato <michele.simionato@gmail.com>2018-04-15 10:22:21 +0200
commit1d1316b5f1e6cc7068c0ee2bf7c3c8b19f840c1d (patch)
treed423aa74594ed147e3d59324288da79946daed3d
parente25ae224da9e4a5f7ded2ff711ddef2ac9e90885 (diff)
downloadpython-decorator-git-1d1316b5f1e6cc7068c0ee2bf7c3c8b19f840c1d.tar.gz
Fixed tests
-rw-r--r--src/decorator.py9
-rw-r--r--src/tests/documentation.py15
2 files changed, 9 insertions, 15 deletions
diff --git a/src/decorator.py b/src/decorator.py
index fc67e84..efd0b1b 100644
--- a/src/decorator.py
+++ b/src/decorator.py
@@ -250,13 +250,9 @@ def decorator(caller, _func=None):
else:
name = caller.__name__
doc = caller.__doc__
- a = getfullargspec(caller)
- defargs = a.args[1:]
- nargs = len(a.args[1:])
+ nargs = caller.__code__.co_argcount
ndefs = len(caller.__defaults__ or ())
- if ndefs < nargs:
- caller.__defaults__ = (None,) * (nargs - ndefs)
- defaultargs = ', '.join(defargs)
+ defaultargs = ', '.join(caller.__code__.co_varnames[nargs-ndefs:nargs])
if defaultargs:
defaultargs += ','
defaults = caller.__defaults__
@@ -273,7 +269,6 @@ def decorator(caller, _func=None):
dec.__defaults__ = (None,) + defaults
return dec
-
# ####################### contextmanager ####################### #
try: # Python >= 3.2
diff --git a/src/tests/documentation.py b/src/tests/documentation.py
index df7cfc5..c010c58 100644
--- a/src/tests/documentation.py
+++ b/src/tests/documentation.py
@@ -203,9 +203,8 @@ calling the function with more than one argument raises an error:
TypeError: f1() takes exactly 1 positional argument (2 given)
Notice that ``inspect.getfullargspec``
-will give the wrong signature. This even occurs in Python 3.5,
-although both functions were deprecated in that release.
-
+will give the wrong signature, even in the latest Python, i.e. version 3.6
+at the time of writing.
The solution
-----------------------------------------
@@ -413,7 +412,7 @@ available. For instance:
.. code-block:: python
- >>> @blocking("Please wait ...")
+ >>> @blocking(msg="Please wait ...")
... def read_data():
... time.sleep(3) # simulate a blocking resource
... return "some data"
@@ -609,7 +608,7 @@ Here is what happens:
an instance of ``FunctionMaker`` is created with the attributes
``args``, ``varargs``, ``keywords``, and ``defaults``.
(These mirror the return values of the standard library's
- ``inspect.getargspec``.)
+ ``inspect.getfullargspec``.)
- For each item in ``args`` (a list of strings of the names of all required
arguments), an attribute ``arg0``, ``arg1``, ..., ``argN`` is also generated.
@@ -625,8 +624,8 @@ followed by a tuple of defaults:
>>> f1 = FunctionMaker.create(
... 'f1(a, b)', 'f(a, b)', dict(f=f), addsource=True, defaults=(None,))
- >>> print(getargspec(f1))
- ArgSpec(args=['a', 'b'], varargs=None, varkw=None, defaults=(None,))
+ >>> print(getfullargspec(f1))
+ FullArgSpec(args=['a', 'b'], varargs=None, varkw=None, defaults=(None,), kwonlyargs=[], kwonlydefaults=None, annotations={})
Getting the source code
@@ -1322,7 +1321,7 @@ Here is an example:
In order to introspect functions with annotations, one needs the
utility ``inspect.getfullargspec`` (introduced in Python 3, then
-deprecated in Python 3.5, in favor of ``inspect.signature``):
+deprecated in Python 3.5, then undeprecated in Python 3.6):
.. code-block:: python