Generate a shadow glue method for a property setter. For interpreted subclasses, property setters can't be called via the internal __mypyc_setter__ method. Instead, use Python's setattr to set the property via the standard descriptor protocol.
(
builder: IRBuilder, sig: FuncSignature, target: FuncIR, cls: ClassIR, base: ClassIR, line: int
)
| 850 | |
| 851 | |
| 852 | def gen_glue_property_setter( |
| 853 | builder: IRBuilder, sig: FuncSignature, target: FuncIR, cls: ClassIR, base: ClassIR, line: int |
| 854 | ) -> FuncIR: |
| 855 | """Generate a shadow glue method for a property setter. |
| 856 | |
| 857 | For interpreted subclasses, property setters can't be called via the |
| 858 | internal __mypyc_setter__<name> method. Instead, use Python's setattr |
| 859 | to set the property via the standard descriptor protocol. |
| 860 | """ |
| 861 | builder.enter() |
| 862 | builder.ret_types[-1] = sig.ret_type |
| 863 | |
| 864 | rt_args = list(sig.args) |
| 865 | rt_args[0] = RuntimeArg(sig.args[0].name, RInstance(cls)) |
| 866 | |
| 867 | arg_info = get_args(builder, rt_args, line) |
| 868 | args = arg_info.args |
| 869 | |
| 870 | self_arg = args[0] |
| 871 | value_arg = args[1] |
| 872 | |
| 873 | # Extract the property name from "__mypyc_setter__<name>" |
| 874 | assert target.name.startswith(PROPSET_PREFIX) |
| 875 | prop_name = target.name[len(PROPSET_PREFIX) :] |
| 876 | |
| 877 | builder.primitive_op( |
| 878 | py_setattr_op, |
| 879 | [ |
| 880 | self_arg, |
| 881 | builder.load_str(prop_name), |
| 882 | builder.coerce(value_arg, object_rprimitive, line), |
| 883 | ], |
| 884 | line, |
| 885 | ) |
| 886 | retval = builder.coerce(builder.none(), sig.ret_type, line) |
| 887 | builder.add(Return(retval)) |
| 888 | |
| 889 | arg_regs, _, blocks, return_type, _ = builder.leave() |
| 890 | return FuncIR( |
| 891 | FuncDecl( |
| 892 | target.name + "__" + base.name + "_glue", |
| 893 | cls.name, |
| 894 | builder.module_name, |
| 895 | FuncSignature(rt_args, return_type), |
| 896 | ), |
| 897 | arg_regs, |
| 898 | blocks, |
| 899 | ) |
| 900 | |
| 901 | |
| 902 | def get_func_target(builder: IRBuilder, fdef: FuncDef) -> AssignmentTarget: |
no test coverage detected
searching dependent graphs…