(builder: IRBuilder, dec: Decorator)
| 108 | |
| 109 | |
| 110 | def 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 | |
| 141 | def transform_lambda_expr(builder: IRBuilder, expr: LambdaExpr) -> Value: |
no test coverage detected
searching dependent graphs…