|
9 | 9 |
|
10 | 10 | from python_toolbox.third_party import decorator as michele_decorator_module |
11 | 11 |
|
12 | | -def decorator(caller, func=None): |
13 | | - ''' |
14 | | - Create a decorator. |
15 | | -
|
16 | | - `decorator(caller)` converts a caller function into a decorator; |
17 | | - `decorator(caller, func)` decorates a function using a caller. |
18 | | - ''' |
19 | | - if func is not None: # returns a decorated function |
20 | | - evaldict = func.__globals__.copy() |
21 | | - evaldict['_call_'] = caller |
22 | | - evaldict['_func_'] = func |
23 | | - result = michele_decorator_module.FunctionMaker.create( |
24 | | - func, "return _call_(_func_, %(shortsignature)s)", |
25 | | - evaldict, undecorated=func) |
26 | | - result.__wrapped__ = func |
27 | | - return result |
28 | | - else: # returns a decorator |
29 | | - if isinstance(caller, functools.partial): |
30 | | - return functools.partial(decorator, caller) |
31 | | - # otherwise assume caller is a function |
32 | | - first = inspect.getargspec(caller)[0][0] # first arg |
33 | | - evaldict = caller.__globals__.copy() |
34 | | - evaldict['_call_'] = caller |
35 | | - evaldict['decorator'] = decorator |
36 | | - return michele_decorator_module.FunctionMaker.create( |
37 | | - '%s(%s)' % (caller.__name__, first), |
38 | | - 'return decorator(_call_, %s)' % first, |
39 | | - evaldict, undecorated=caller, |
40 | | - doc=caller.__doc__, module=caller.__module__) |
41 | | - |
42 | 12 |
|
43 | 13 | def helpful_decorator_builder(decorator_builder): |
44 | 14 | ''' |
@@ -89,4 +59,4 @@ def inner(same_decorator_builder, *args, **kwargs): |
89 | 59 | else: |
90 | 60 | return decorator_builder(*args, **kwargs) |
91 | 61 |
|
92 | | - return decorator(inner, decorator_builder) |
| 62 | + return functools.wraps(inner)(decorator_builder) |
0 commit comments