-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathtest.py
More file actions
75 lines (51 loc) · 873 Bytes
/
test.py
File metadata and controls
75 lines (51 loc) · 873 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import functools
def annotate(value):
def inner(func):
func.annotation = value
return func
return inner
def wraps1(func):
def wrapper(*args):
res = func(*args)
return res
return wrapper
def wraps2(func):
@functools.wraps(func)
def wrapper(*args):
res = func(*args)
return res
return wrapper
@annotate(100)
def func1():
pass
@wraps1
def func2():
pass
@wraps2
def func3():
pass
func1
func2
func3
#Fancy decorators
def register(name=None):
def decorator(func):
if not callable(func):
raise ValueError("not a callable")
return func
if callable(name):
return decorator(name)
else:
return decorator
@register(17)
def foo():
pass
foo
@register
def bar():
pass
bar()
@register()
def baz():
pass
baz()