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

Function generate_methods_table

mypyc/codegen/emitclass.py:1011–1044  ·  view source on GitHub ↗
(
    cl: ClassIR, name: str, setup_name: str | None, emitter: Emitter
)

Source from the content-addressed store, hash-verified

1009
1010
1011def generate_methods_table(
1012 cl: ClassIR, name: str, setup_name: str | None, emitter: Emitter
1013) -> None:
1014 emitter.emit_line(f"static PyMethodDef {name}[] = {{")
1015 if setup_name:
1016 # Store pointer to the setup function so it can be resolved dynamically
1017 # in case of instance creation in __new__.
1018 # CPy_SetupObject expects this method to be the first one in tp_methods.
1019 emitter.emit_line(
1020 f'{{"__internal_mypyc_setup", (PyCFunction){setup_name}, METH_O, NULL}},'
1021 )
1022 for fn in cl.methods.values():
1023 if fn.decl.is_prop_setter or fn.decl.is_prop_getter or fn.internal:
1024 continue
1025 emitter.emit_line(f'{{"{fn.name}",')
1026 emitter.emit_line(f" (PyCFunction){PREFIX}{fn.cname(emitter.names)},")
1027 flags = ["METH_FASTCALL", "METH_KEYWORDS"]
1028 if fn.decl.kind == FUNC_STATICMETHOD:
1029 flags.append("METH_STATIC")
1030 elif fn.decl.kind == FUNC_CLASSMETHOD:
1031 flags.append("METH_CLASS")
1032
1033 doc = native_function_doc_initializer(fn)
1034 emitter.emit_line(" {}, PyDoc_STR({})}},".format(" | ".join(flags), doc))
1035
1036 # Provide a default __getstate__ and __setstate__
1037 if not cl.has_method("__setstate__") and not cl.has_method("__getstate__"):
1038 emitter.emit_lines(
1039 '{"__setstate__", (PyCFunction)CPyPickle_SetState, METH_O, NULL},',
1040 '{"__getstate__", (PyCFunction)CPyPickle_GetState, METH_NOARGS, NULL},',
1041 )
1042
1043 emitter.emit_line("{NULL} /* Sentinel */")
1044 emitter.emit_line("};")
1045
1046
1047def generate_side_table_for_class(

Callers 1

generate_classFunction · 0.85

Calls 9

valuesMethod · 0.80
appendMethod · 0.80
has_methodMethod · 0.80
emit_lineMethod · 0.45
cnameMethod · 0.45
formatMethod · 0.45
joinMethod · 0.45
emit_linesMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…