In this case I want to pass _source_dir_abs:str
into decorator.
I tried to mimic the same process that Flask has for routing to pass parameter from decorator to function it is decorated. But this makes the parameter interpreted as a literal string and not as a variable.
@dec_check_abs("<_source_dir_abs>")
def walk_return_dir_nofolder(_source_dir_abs:str) -> list:
w = walk(_source_dir_abs)
d = [d for d, fol, fil in w if len(fol) == 0]
return d
I tried with @dec_check_abs(_source_dir_abs)
it returns an error of NameError: name 'source_dir_abs' is not defined
def dec_check_abs(*args_1):
def decorator(_func:FT):
def wrapper(*args_2, **kwargs):
for i in args_1:
if not check_abs(i):
"""Raise warning."""
napw()
if _func.__annotations__["return"] == bool:
return False
else:
return None
return _func(*args_2, **kwargs)
return wrapper
return decorator
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…