MCPcopy Index your code
hub / github.com/python/cpython / handle_new_or_init

Method handle_new_or_init

Tools/clinic/libclinic/parse_args.py:857–893  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

855 condition=include.condition)
856
857 def handle_new_or_init(self) -> None:
858 self.methoddef_define = ''
859
860 if self.func.kind is METHOD_NEW:
861 self.parser_prototype = PARSER_PROTOTYPE_KEYWORD
862 else:
863 self.return_value_declaration = "int return_value = -1;"
864 self.parser_prototype = PARSER_PROTOTYPE_KEYWORD___INIT__
865
866 fields: list[str] = list(self.parser_body_fields)
867 parses_positional = 'METH_NOARGS' not in self.flags
868 parses_keywords = 'METH_KEYWORDS' in self.flags
869 if parses_keywords:
870 assert parses_positional
871
872 if self.requires_defining_class:
873 raise ValueError("Slot methods cannot access their defining class.")
874
875 if not parses_keywords:
876 self.declarations = '{base_type_ptr}'
877 self.codegen.add_include('pycore_modsupport.h',
878 '_PyArg_NoKeywords()')
879 fields.insert(0, libclinic.normalize_snippet("""
880 if ({self_type_check}!_PyArg_NoKeywords("{name}", kwargs)) {{
881 goto exit;
882 }}
883 """, indent=4))
884 if not parses_positional:
885 self.codegen.add_include('pycore_modsupport.h',
886 '_PyArg_NoPositional()')
887 fields.insert(0, libclinic.normalize_snippet("""
888 if ({self_type_check}!_PyArg_NoPositional("{name}", args)) {{
889 goto exit;
890 }}
891 """, indent=4))
892
893 self.parser_body(*fields, declarations=self.declarations)
894
895 def process_methoddef(self, clang: CLanguage) -> None:
896 methoddef_cast_end = ""

Callers 1

parse_argsMethod · 0.95

Calls 4

parser_bodyMethod · 0.95
listClass · 0.85
add_includeMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected