MCPcopy
hub / github.com/rocky/python-uncompyle6 / build_class

Method build_class

uncompyle6/semantics/pysource.py:1035–1173  ·  view source on GitHub ↗

Dump class definition, doc string and class body.

(self, code)

Source from the content-addressed store, hash-verified

1033 return f"({name}"
1034
1035 def build_class(self, code):
1036 """Dump class definition, doc string and class body."""
1037
1038 assert iscode(code)
1039 self.classes.append(self.currentclass)
1040 code = Code(code, self.scanner, self.currentclass)
1041
1042 indent = self.indent
1043 # self.println(indent, '#flags:\t', int(code.co_flags))
1044 ast = self.build_ast(code._tokens, code._customize, code)
1045
1046 # save memory by deleting no-longer-used structures
1047 code._tokens = None
1048
1049 if ast[0] == "sstmt":
1050 ast[0] = ast[0][0]
1051 first_stmt = ast[0]
1052
1053 if ast[0] == "docstring":
1054 self.println(self.traverse(ast[0]))
1055 del ast[0]
1056 first_stmt = ast[0]
1057
1058 if (3, 0) <= self.version <= (3, 3):
1059 try:
1060 if first_stmt == "store_locals":
1061 if self.hide_internal:
1062 del ast[0]
1063 if ast[0] == "sstmt":
1064 ast[0] = ast[0][0]
1065 first_stmt = ast[0]
1066 except Exception:
1067 pass
1068
1069 try:
1070 if first_stmt == NAME_MODULE:
1071 if self.hide_internal:
1072 del ast[0]
1073 first_stmt = ast[0]
1074 pass
1075 except Exception:
1076 pass
1077
1078 have_qualname = False
1079 if len(ast):
1080 if ast[0] == "sstmt":
1081 ast[0] = ast[0][0]
1082 first_stmt = ast[0]
1083
1084 if self.version < (3, 0):
1085 # Should we ditch this in favor of the "else" case?
1086 qualname = ".".join(self.classes)
1087 qual_name_tree = SyntaxTree(
1088 "assign",
1089 [
1090 SyntaxTree("expr", [Token("LOAD_CONST", pattr=qualname)]),
1091 SyntaxTree("store", [Token("STORE_NAME", pattr="__qualname__")]),
1092 ],

Callers 4

n_classdef36Function · 0.80
n_classdefMethod · 0.80
n_classdefMethod · 0.80
n_classdef3Function · 0.80

Calls 12

build_astMethod · 0.95
printlnMethod · 0.95
traverseMethod · 0.95
gen_sourceMethod · 0.95
CodeClass · 0.90
SyntaxTreeClass · 0.90
TokenClass · 0.90
is_docstringFunction · 0.90
print_docstringFunction · 0.90
appendMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected