MCPcopy Index your code
hub / github.com/PyGithub/PyGithub / visit_FunctionDef

Method visit_FunctionDef

scripts/openapi.py:666–805  ·  view source on GitHub ↗
(self, node: cst.FunctionDef)

Source from the content-addressed store, hash-verified

664 return [rt.strip().replace('"', "") for rt in types]
665
666 def visit_FunctionDef(self, node: cst.FunctionDef) -> None:
667 method_name = node.name.value
668 decorators = self.get_decorators(node.decorators, "method_returns")
669 path_property = next(
670 iter([decorator["schema_property"] for decorator in decorators if "schema_property" in decorator]), None
671 )
672 returns = self.return_types(cst.Module([]).code_for_node(node.returns.annotation) if node.returns else None)
673
674 if self.is_github_object_property(node):
675 self._properties[method_name] = {"name": method_name, "returns": returns}
676
677 visitor = SimpleStringCollector()
678 node.body.visit(visitor)
679 if visitor.strings:
680 string = [line for line in visitor.strings[0].splitlines() if ":calls:" in line]
681 if string:
682 fields = string[0].split(":calls:")[1].strip(" `").split(" ", maxsplit=2)
683 verb = fields[0] if len(fields) > 0 else None
684 path = fields[1] if len(fields) > 1 else None
685 path = f"{path}#{path_property}" if path_property else path
686 docs = fields[2] if len(fields) > 2 else None
687 self._methods[method_name] = {
688 "name": method_name,
689 "call": {
690 "verb": verb,
691 "path": path,
692 "docs": docs,
693 },
694 "returns": returns,
695 }
696 if len(fields) > 1:
697 if path not in self._paths:
698 self._paths[path] = {}
699 if verb not in self._paths[path]:
700 self._paths[path][verb] = {"methods": []}
701 self._paths[path][verb]["methods"].append(
702 {
703 "class": self.current_class_name,
704 "name": method_name,
705 "returns": returns,
706 }
707 )
708
709 # check if method (VERB) is same as in the code
710 if len(fields) > 0 and self._method_verbs is not None:
711 quoted_verb = f'"{verb}"'
712 full_method_name = f"{self.current_class_name}.{method_name}"
713
714 if full_method_name in self._method_verbs:
715 # these are methods configured in the github/openapi.index.json file
716 known_verb = f'"{self._method_verbs[full_method_name]}"'
717 if known_verb != quoted_verb:
718 print(
719 f"Method {full_method_name} is known to call {known_verb}, "
720 f"but doc-string says {quoted_verb}"
721 )
722 else:
723 # detect method from code

Callers

nothing calls this directly

Calls 6

return_typesMethod · 0.95
DictKeyCollectorClass · 0.85
get_decoratorsMethod · 0.80

Tested by

no test coverage detected