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

Function gen_glue_property

mypyc/irbuild/function.py:808–849  ·  view source on GitHub ↗

Generate glue methods for properties that mediate between different subclass types. Similarly to methods, properties of derived types can be covariantly subtyped. Thus, properties also require glue. However, this only requires the return type to change. Further, instead of a method call

(
    builder: IRBuilder,
    sig: FuncSignature,
    target: FuncIR,
    cls: ClassIR,
    base: ClassIR,
    line: int,
    do_pygetattr: bool,
)

Source from the content-addressed store, hash-verified

806
807
808def gen_glue_property(
809 builder: IRBuilder,
810 sig: FuncSignature,
811 target: FuncIR,
812 cls: ClassIR,
813 base: ClassIR,
814 line: int,
815 do_pygetattr: bool,
816) -> FuncIR:
817 """Generate glue methods for properties that mediate between different subclass types.
818
819 Similarly to methods, properties of derived types can be covariantly subtyped. Thus,
820 properties also require glue. However, this only requires the return type to change.
821 Further, instead of a method call, an attribute get is performed.
822
823 If do_pygetattr is True, then get the attribute using the Python C
824 API instead of a native call.
825 """
826 builder.enter()
827
828 rt_arg = RuntimeArg(SELF_NAME, RInstance(cls))
829 self_target = builder.add_self_to_env(cls)
830 arg = builder.read(self_target, line)
831 builder.ret_types[-1] = sig.ret_type
832 if do_pygetattr:
833 retval = builder.py_get_attr(arg, target.name, line)
834 else:
835 retval = builder.add(GetAttr(arg, target.name, line))
836 retbox = builder.coerce(retval, sig.ret_type, line)
837 builder.add(Return(retbox))
838
839 args, _, blocks, return_type, _ = builder.leave()
840 return FuncIR(
841 FuncDecl(
842 target.name + "__" + base.name + "_glue",
843 cls.name,
844 builder.module_name,
845 FuncSignature([rt_arg], return_type),
846 ),
847 args,
848 blocks,
849 )
850
851
852def gen_glue_property_setter(

Callers 1

gen_glueFunction · 0.85

Calls 14

RuntimeArgClass · 0.90
RInstanceClass · 0.90
GetAttrClass · 0.90
ReturnClass · 0.90
FuncIRClass · 0.90
FuncDeclClass · 0.90
FuncSignatureClass · 0.90
add_self_to_envMethod · 0.80
leaveMethod · 0.80
enterMethod · 0.45
readMethod · 0.45
py_get_attrMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…