From 4d259b360a1eb7d2ab8c4db9d6becd9c70ec7aaf Mon Sep 17 00:00:00 2001 From: Michele Simionato Date: Sat, 16 Mar 2019 06:41:08 +0100 Subject: Reverted the decorator factory sintax to v4.2 and bumped the release to 4.4 --- src/tests/documentation.py | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) (limited to 'src/tests') 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: + +``` + ``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 """ -- cgit v1.2.1