summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichele Simionato <michele.simionato@gmail.com>2019-03-16 06:41:08 +0100
committerMichele Simionato <michele.simionato@gmail.com>2019-03-16 06:41:08 +0100
commit4d259b360a1eb7d2ab8c4db9d6becd9c70ec7aaf (patch)
tree74ff596eb06ce5f038d799795188f99c9e1d5839 /src
parent976c5ec2a1453ce2b63e13e885b4d7ab9b34be6a (diff)
downloadpython-decorator-git-4d259b360a1eb7d2ab8c4db9d6becd9c70ec7aaf.tar.gz
Reverted the decorator factory sintax to v4.2 and bumped the release to 4.4
Diffstat (limited to 'src')
-rw-r--r--src/decorator.py6
-rw-r--r--src/tests/documentation.py33
2 files changed, 28 insertions, 11 deletions
diff --git a/src/decorator.py b/src/decorator.py
index 56068e9..34fd527 100644
--- a/src/decorator.py
+++ b/src/decorator.py
@@ -40,7 +40,7 @@ import operator
import itertools
import collections
-__version__ = '4.3.2'
+__version__ = '4.4.0'
if sys.version >= '3':
from inspect import getfullargspec
@@ -284,12 +284,12 @@ def decorator(caller, _func=None):
doc = caller.__call__.__doc__
evaldict = dict(_call=caller, _decorate_=decorate)
dec = FunctionMaker.create(
- '%s(%s func)' % (name, defaultargs),
+ '%s(func, %s)' % (name, defaultargs),
'if func is None: return lambda func: _decorate_(func, _call, (%s))\n'
'return _decorate_(func, _call, (%s))' % (defaultargs, defaultargs),
evaldict, doc=doc, module=caller.__module__, __wrapped__=caller)
if defaults:
- dec.__defaults__ = defaults + (None,)
+ dec.__defaults__ = (None,) + defaults
return dec
diff --git a/src/tests/documentation.py b/src/tests/documentation.py
index 2e6b473..8e9adf8 100644
--- a/src/tests/documentation.py
+++ b/src/tests/documentation.py
@@ -430,7 +430,7 @@ the resource is unavailable, and the intended result if the resource is
available. For instance:
```python
->>> @blocking("Please wait ...")
+>>> @blocking(msg="Please wait ...")
... def read_data():
... time.sleep(3) # simulate a blocking resource
... return "some data"
@@ -461,6 +461,15 @@ where ``restricted`` is a decorator factory defined as follows
$$restricted
+Notice that if you forget to use the keyword argument notation, i.e. if you
+write ``restricted(User)`` instead of ``restricted(user_class=User)`` you
+will get an error
+
+```python
+TypeError: You are decorating a non function: <class '__main__.User'>
+
+```
+
``decorator(cls)``
--------------------------------------------
@@ -1560,15 +1569,15 @@ def restricted(func, user_class=User, *args, **kw):
class Action(object):
- @restricted(User)
+ @restricted(user_class=User)
def view(self):
"Any user can view objects"
- @restricted(PowerUser)
+ @restricted(user_class=PowerUser)
def insert(self):
"Only power users can insert objects"
- @restricted(Admin)
+ @restricted(user_class=Admin)
def delete(self):
"Only the admin can delete objects"
@@ -1857,11 +1866,19 @@ def warn_slow(func, duration=0, *args, **kwargs):
return res
-@warn_slow()
-def operation():
+@warn_slow() # with parens
+def operation1():
+ """
+ >>> operation1()
+ operation1 is slow
+ """
+
+
+@warn_slow # without parens
+def operation2():
"""
- >>> operation()
- operation is slow
+ >>> operation2()
+ operation2 is slow
"""