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

Function generate_getseter_declarations

mypyc/codegen/emitclass.py:1058–1093  ·  view source on GitHub ↗
(cl: ClassIR, emitter: Emitter)

Source from the content-addressed store, hash-verified

1056
1057
1058def generate_getseter_declarations(cl: ClassIR, emitter: Emitter) -> None:
1059 if not cl.is_trait:
1060 for attr in cl.attributes:
1061 emitter.emit_line("static PyObject *")
1062 emitter.emit_line(
1063 "{}({} *self, void *closure);".format(
1064 getter_name(cl, attr, emitter.names), cl.struct_name(emitter.names)
1065 )
1066 )
1067 emitter.emit_line("static int")
1068 emitter.emit_line(
1069 "{}({} *self, PyObject *value, void *closure);".format(
1070 setter_name(cl, attr, emitter.names), cl.struct_name(emitter.names)
1071 )
1072 )
1073
1074 for prop, (getter, setter) in cl.properties.items():
1075 if getter.decl.implicit:
1076 continue
1077
1078 # Generate getter declaration
1079 emitter.emit_line("static PyObject *")
1080 emitter.emit_line(
1081 "{}({} *self, void *closure);".format(
1082 getter_name(cl, prop, emitter.names), cl.struct_name(emitter.names)
1083 )
1084 )
1085
1086 # Generate property setter declaration if a setter exists
1087 if setter:
1088 emitter.emit_line("static int")
1089 emitter.emit_line(
1090 "{}({} *self, PyObject *value, void *closure);".format(
1091 setter_name(cl, prop, emitter.names), cl.struct_name(emitter.names)
1092 )
1093 )
1094
1095
1096def generate_getseters_table(cl: ClassIR, name: str, emitter: Emitter) -> None:

Callers 1

generate_classFunction · 0.85

Calls 6

getter_nameFunction · 0.85
setter_nameFunction · 0.85
emit_lineMethod · 0.45
formatMethod · 0.45
struct_nameMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…