MCPcopy Index your code
hub / github.com/python/mypy / load_decorated_func

Function load_decorated_func

mypyc/irbuild/function.py:611–630  ·  view source on GitHub ↗

Apply decorators to a function. Given a decorated FuncDef and an instance of the callable class representing that FuncDef, apply the corresponding decorator functions on that decorated FuncDef and return the decorated function.

(builder: IRBuilder, fdef: FuncDef, orig_func_reg: Value)

Source from the content-addressed store, hash-verified

609
610
611def load_decorated_func(builder: IRBuilder, fdef: FuncDef, orig_func_reg: Value) -> Value:
612 """Apply decorators to a function.
613
614 Given a decorated FuncDef and an instance of the callable class
615 representing that FuncDef, apply the corresponding decorator
616 functions on that decorated FuncDef and return the decorated
617 function.
618 """
619 if not is_decorated(builder, fdef):
620 # If there are no decorators associated with the function, then just return the
621 # original function.
622 return orig_func_reg
623
624 decorators = builder.fdefs_to_decorators[fdef]
625 func_reg = orig_func_reg
626 for d in reversed(decorators):
627 decorator = d.accept(builder.visitor)
628 assert isinstance(decorator, Value), decorator
629 func_reg = builder.py_call(decorator, [func_reg], func_reg.line)
630 return func_reg
631
632
633def is_decorated(builder: IRBuilder, fdef: FuncDef) -> bool:

Callers 3

transform_decoratorFunction · 0.85
handle_ext_methodFunction · 0.85
handle_non_ext_methodFunction · 0.85

Calls 5

is_decoratedFunction · 0.85
reversedFunction · 0.85
isinstanceFunction · 0.85
acceptMethod · 0.45
py_callMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…