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

Function transform_decorator

mypyc/irbuild/function.py:110–138  ·  view source on GitHub ↗
(builder: IRBuilder, dec: Decorator)

Source from the content-addressed store, hash-verified

108
109
110def transform_decorator(builder: IRBuilder, dec: Decorator) -> None:
111 sig = builder.mapper.fdef_to_sig(dec.func, builder.options.strict_dunders_typing)
112 func_ir, func_reg = gen_func_item(builder, dec.func, dec.func.name, sig)
113 decorated_func: Value | None = None
114 if func_reg:
115 decorated_func = load_decorated_func(builder, dec.func, func_reg)
116 builder.assign(get_func_target(builder, dec.func), decorated_func, dec.func.line)
117 # If the prebuild pass didn't put this function in the function to decorators map (for example
118 # if this is a registered singledispatch implementation with no other decorators), we should
119 # treat this function as a regular function, not a decorated function
120 elif dec.func in builder.fdefs_to_decorators:
121 # Obtain the function name in order to construct the name of the helper function.
122 name = dec.func.fullname.split(".")[-1]
123
124 # Load the callable object representing the non-decorated function, and decorate it.
125 orig_func = builder.load_global_str(name, dec.line)
126 decorated_func = load_decorated_func(builder, dec.func, orig_func)
127
128 if decorated_func is not None:
129 # Set the callable object representing the decorated function as a global.
130 builder.call_c(
131 exact_dict_set_item_op,
132 [builder.load_globals_dict(), builder.load_str(dec.func.name), decorated_func],
133 decorated_func.line,
134 )
135
136 maybe_insert_into_registry_dict(builder, dec.func)
137
138 builder.functions.append(func_ir)
139
140
141def transform_lambda_expr(builder: IRBuilder, expr: LambdaExpr) -> Value:

Callers 1

visit_decoratorMethod · 0.90

Calls 12

gen_func_itemFunction · 0.85
load_decorated_funcFunction · 0.85
get_func_targetFunction · 0.85
fdef_to_sigMethod · 0.80
splitMethod · 0.80
load_global_strMethod · 0.80
load_globals_dictMethod · 0.80
appendMethod · 0.80
assignMethod · 0.45
call_cMethod · 0.45
load_strMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…