-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdecorator_2.py
More file actions
executable file
·58 lines (42 loc) · 1 KB
/
decorator_2.py
File metadata and controls
executable file
·58 lines (42 loc) · 1 KB
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
import functools
def integer_arguments(func):
def wrapped(x, y):
assert isinstance(x, int)
assert isinstance(y, int)
return func(x, y)
return wrapped
def integer_arguments_v2(func):
@functools.wraps(func)
def wrapped(x, y):
assert isinstance(x, int)
assert isinstance(y, int)
return func(x, y)
return wrapped
@integer_arguments_v2
def multiply(x, y):
"""Multiplies two integers
Args:
x (int): First number
y (int): Second number
Returns:
int: Product
"""
return x * y
@integer_arguments
def add(x, y):
"""Adds two integers
Args:
x (int): First integer
y (int): Second integer
Returns:
int: Sum
"""
return x + y
def main():
print("Name is:", add.__name__)
print(help(add))
print()
print("Name is:", multiply.__name__)
print(help(multiply))
if __name__ == '__main__':
main()