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

Method parse_cloned_function

Tools/clinic/libclinic/dsl_parser.py:631–672  ·  view source on GitHub ↗
(self, names: FunctionNames, existing: str)

Source from the content-addressed store, hash-verified

629 return CReturnConverter()
630
631 def parse_cloned_function(self, names: FunctionNames, existing: str) -> None:
632 full_name, c_basename = names
633 fields = [x.strip() for x in existing.split('.')]
634 function_name = fields.pop()
635 module, cls = self.clinic._module_and_class(fields)
636 parent = cls or module
637
638 for existing_function in parent.functions:
639 if existing_function.name == function_name:
640 break
641 else:
642 print(f"{cls=}, {module=}, {existing=}", file=sys.stderr)
643 print(f"{(cls or module).functions=}", file=sys.stderr)
644 fail(f"Couldn't find existing function {existing!r}!")
645
646 fields = [x.strip() for x in full_name.split('.')]
647 function_name = fields.pop()
648 module, cls = self.clinic._module_and_class(fields)
649
650 overrides: dict[str, Any] = {
651 "name": function_name,
652 "full_name": full_name,
653 "module": module,
654 "cls": cls,
655 "c_basename": c_basename,
656 "docstring": "",
657 }
658 if not (existing_function.kind is self.kind and
659 existing_function.coexist == self.coexist):
660 # Allow __new__ or __init__ methods.
661 if existing_function.kind.new_or_init:
662 overrides["kind"] = self.kind
663 # Future enhancement: allow custom return converters
664 overrides["return_converter"] = CReturnConverter()
665 else:
666 fail("'kind' of function and cloned function don't match! "
667 "(@classmethod/@staticmethod/@coexist)")
668 function = existing_function.copy(**overrides)
669 self.function = function
670 self.block.signatures.append(function)
671 (cls or module).functions.append(function)
672 self.next(self.state_function_docstring)
673
674 def state_modulename_name(self, line: str) -> None:
675 # looking for declaration, which establishes the leftmost column

Callers 1

state_modulename_nameMethod · 0.95

Calls 9

nextMethod · 0.95
failFunction · 0.90
CReturnConverterClass · 0.90
_module_and_classMethod · 0.80
stripMethod · 0.45
splitMethod · 0.45
popMethod · 0.45
copyMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected