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

Function gen_glue_property_setter

mypyc/irbuild/function.py:852–899  ·  view source on GitHub ↗

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
)

Source from the content-addressed store, hash-verified

850
851
852def 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&#x27;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
902def get_func_target(builder: IRBuilder, fdef: FuncDef) -> AssignmentTarget:

Callers 1

gen_glueFunction · 0.85

Calls 15

RuntimeArgClass · 0.90
RInstanceClass · 0.90
ReturnClass · 0.90
FuncIRClass · 0.90
FuncDeclClass · 0.90
FuncSignatureClass · 0.90
listClass · 0.85
get_argsFunction · 0.85
lenFunction · 0.85
leaveMethod · 0.80
enterMethod · 0.45
startswithMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…