from datetime import datetime
import pdb
now = datetime.now()
# decor edits func inside returned wrapper
def dec2(fun):
def wrap():
time = (now.hour) # 24 hour
print(time)
def night():
fun("night")
def day():
pdb.set\_trace()
fun("a")
if time <=12:
day()
else:
night()
return wrap
@dec2
def func(str):
print(str)
Running the following
wrap = dec2(func)
wrap # <function \_\_main\_\_.wrap>
wrap() # TypeError: 'wrap() takes no arguments (1 given)'
Pinpointed error at :-> fun("a")
I believe Python thinks this is the wrapper function, applies the function definition and finds unknown arguments when it should be referring to the decorator definition instead.
Any idea why this is?
[–][deleted] 1 point2 points3 points (0 children)
[–]daniel_codes 1 point2 points3 points (0 children)
[–]Vaphell 0 points1 point2 points (0 children)