-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil_decorator.py
More file actions
40 lines (28 loc) · 868 Bytes
/
util_decorator.py
File metadata and controls
40 lines (28 loc) · 868 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from functools import wraps
def log(fun):
@wraps(fun)
def new_fun(*args, **kwargs):
'''
@wraps(fun) can help to return real fun name when call fun.__name__
'''
funName = fun.__name__
argList = [str(x) for x in args]
kwargsList = [f'{x} = {str(kwargs[x])}' for x in kwargs]
if len(argList) > 0:
argList = f'{", ".join(argList)}'
else:
argList = ""
if len(kwargsList) > 0:
kwargsList = f' , {", ".join(kwargsList)}'
else:
kwargsList = ""
print(f'{funName}( {argList}{kwargsList} )')
return fun(*args, **kwargs)
return new_fun
def chain(fun):
"""return self for the function"""
@wraps(fun)
def new_fun(*args, **kwargs):
fun(*args, **kwargs)
return args[0]
return new_fun