python - Would decorated function calling another decorator function return normally? -
how control flow work in case of decorators ? there anyway can modify calleedec , make not return caller after getting invoked ? not desired scenario see similar bug wondering if thats possible ? isn't normal functions ?
trying debug issue - hit first pdb not second pdb in scenario below ?
both decorated functions .
@cooldec() def caller(): import pdb;pbd.set_trace() # hits here callee() import pdb;pdb.set_trace() # not here @calleedec() def callee(): return "okay
edit:
raising error 1 scenario no error trace .
i can see case callee's decorator in infinite loop or not able job (taking long time) , can happen .
decorated functions plain functions, , have nothing special them regarding program flow.
when in doubt, try expand decorator , see if clearer:
def calleedec(callee_fn): def wrapped(): print("running callee") callee_fn() return wrapped def callee(): return "okay" callee = calleedec(callee) def cooldec(fn): def wrapped(): print("running caller") return fn() return wrapped @cooldec def caller(): print("caller: start") callee() print("caller: end") caller() # running caller # caller: start # running callee # caller: end
to avoid callee hijacking flow , not returning caller function need serious black magic stack. don't think should worry this.
if not hitting second pdb breakpoint, may happening in callee function.
Comments
Post a Comment