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

Method leave_Module

scripts/openapi.py:869–1003  ·  view source on GitHub ↗
(self, original_node: Module, updated_node: Module)

Source from the content-addressed store, hash-verified

867 raise ValueError("Unsupported data type", data_type)
868
869 def leave_Module(self, original_node: Module, updated_node: Module) -> Module:
870 i = 0
871 node = updated_node
872
873 # add from __future__ import annotations if not the first import
874 node = self.add_future_import(node)
875
876 property_classes = {
877 ghc
878 for p in self.all_properties
879 for ghc in self.inner_github_type(p.data_type)
880 if ghc.module != self.module_name and ghc.name != self.class_name
881 }
882 import_classes = sorted(property_classes, key=lambda c: c.module)
883 typing_classes = sorted(property_classes, key=lambda c: c.module)
884 # TODO: do not import this file itself
885 datetime_exists = False
886 in_github_imports = False
887 needs_datetime_import = any(
888 p.data_type.type == "datetime" for p in self.all_properties if isinstance(p.data_type, PythonType)
889 )
890
891 # insert import classes if needed
892 while (
893 i < len(node.body)
894 and isinstance(node.body[i], cst.SimpleStatementLine)
895 and isinstance(node.body[i].body[0], (cst.Import, cst.ImportFrom))
896 ):
897 if self.is_datetime_import(node.body[i].body[0]):
898 datetime_exists = True
899
900 if not in_github_imports and self.is_github_import(node.body[i].body[0]):
901 in_github_imports = True
902
903 # emit datetime import if needed
904 if needs_datetime_import and not datetime_exists:
905 node = self.add_datetime_import(node, i)
906 datetime_exists = True
907 i = i + 1
908
909 if in_github_imports and import_classes:
910 import_node = node.body[i].body[0]
911 imported_module = (
912 (
913 "".join("." for _ in import_node.relative)
914 + (
915 (
916 import_node.module.value
917 if isinstance(import_node.module, cst.Name)
918 else import_node.module.attr.value
919 )
920 if import_node.module is not None
921 else ""
922 )
923 )
924 if isinstance(import_node, cst.ImportFrom)
925 else import_node.names[0].name.attr.value
926 )

Callers

nothing calls this directly

Calls 6

inner_github_typeMethod · 0.95
add_future_importMethod · 0.80
is_datetime_importMethod · 0.80
is_github_importMethod · 0.80
add_datetime_importMethod · 0.80
create_attributeMethod · 0.80

Tested by

no test coverage detected