Skip to content

Commit 618652c

Browse files
committed
Returning parameters from decorator
1 parent f430f29 commit 618652c

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

Concepts/decorator.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
def decorator_func(func):
66
def wrapper(*args, **kwargs):
7-
if 7 <= datetime.now().hour < 16:
8-
func(*args, **kwargs)
7+
if 7 <= datetime.now().hour < 18:
8+
#func(*args, **kwargs)
9+
return func(*args,**kwargs)
910
else:
1011
pass # Hush, the neighbors are asleep
1112
return wrapper

Concepts/decorator_call_2.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
##Illustrating the decorator call with arguments concept
22
# Example 1
33
from decorator import decorator_func
4+
import pytest
45

56
@decorator_func
67
def dec_call3(name):
78
print(f"Hi this is the diff file call by {name}")
89

10+
@decorator_func
11+
def dec_call4(name):
12+
print(f"Hi this is the diff file second call by {name}. Returning YAY")
13+
return "YAY"
14+
15+
916
dec_call3("Abhiram")
17+
ret_val = dec_call4("Kratos")
18+
print("Ret val = "+str(ret_val))
19+
20+
try:
21+
assert ret_val == None
22+
except:
23+
assert ret_val == "YAY"

0 commit comments

Comments
 (0)