Dump class definition, doc string and class body.
(self, code)
| 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 | ], |
no test coverage detected