|
1 |
| -# Copyright (c) 2015-2022 by Rocky Bernstein |
| 1 | +# Copyright (c) 2015-2023 by Rocky Bernstein |
2 | 2 | # Copyright (c) 2005 by Dan Pascu <[email protected]>
|
3 | 3 | # Copyright (c) 2000-2002 by hartmut Goebel <[email protected]>
|
4 | 4 | # Copyright (c) 1999 John Aycock
|
|
131 | 131 |
|
132 | 132 | import sys
|
133 | 133 |
|
134 |
| -IS_PYPY = "__pypy__" in sys.builtin_module_names |
135 |
| - |
136 | 134 | from spark_parser import GenericASTTraversal
|
137 | 135 | from xdis import COMPILER_FLAG_BIT, iscode
|
138 | 136 | from xdis.version_info import PYTHON_VERSION_TRIPLE
|
|
143 | 141 | from uncompyle6.scanner import Code, get_scanner
|
144 | 142 | from uncompyle6.scanners.tok import Token
|
145 | 143 | from uncompyle6.semantics.check_ast import checker
|
146 |
| -from uncompyle6.semantics.consts import (ASSIGN_DOC_STRING, ASSIGN_TUPLE_PARAM, |
| 144 | +from uncompyle6.semantics.consts import (ASSIGN_TUPLE_PARAM, |
147 | 145 | INDENT_PER_LEVEL, LINE_LENGTH, MAP,
|
148 | 146 | MAP_DIRECT, NAME_MODULE, NONE, PASS,
|
149 | 147 | PRECEDENCE, RETURN_LOCALS,
|
@@ -178,6 +176,8 @@ def unicode(x): return x
|
178 | 176 | "dups": False,
|
179 | 177 | }
|
180 | 178 |
|
| 179 | +IS_PYPY = "__pypy__" in sys.builtin_module_names |
| 180 | + |
181 | 181 | TREE_DEFAULT_DEBUG = {"before": False, "after": False}
|
182 | 182 |
|
183 | 183 | DEFAULT_DEBUG_OPTS = {
|
@@ -978,7 +978,6 @@ def get_tuple_parameter(self, ast, name):
|
978 | 978 | return result
|
979 | 979 | # return self.traverse(node[1])
|
980 | 980 | return f"({name}"
|
981 |
| - raise Exception("Can't find tuple parameter " + name) |
982 | 981 |
|
983 | 982 | def build_class(self, code):
|
984 | 983 | """Dump class definition, doc string and class body."""
|
@@ -1193,10 +1192,11 @@ def build_ast(
|
1193 | 1192 | del ast # Save memory
|
1194 | 1193 | return transform_tree
|
1195 | 1194 |
|
1196 |
| - # The bytecode for the end of the main routine has a |
1197 |
| - # "return None". However, you can't issue a "return" statement in |
1198 |
| - # main. So as the old cigarette slogan goes: I'd rather switch (the token stream) |
1199 |
| - # than fight (with the grammar to not emit "return None"). |
| 1195 | + # The bytecode for the end of the main routine has a "return |
| 1196 | + # None". However, you can't issue a "return" statement in |
| 1197 | + # main. So as the old cigarette slogan goes: I'd rather switch |
| 1198 | + # (the token stream) than fight (with the grammar to not emit |
| 1199 | + # "return None"). |
1200 | 1200 | if self.hide_internal:
|
1201 | 1201 | if len(tokens) >= 2 and not noneInNames:
|
1202 | 1202 | if tokens[-1].kind in ("RETURN_VALUE", "RETURN_VALUE_LAMBDA"):
|
@@ -1257,6 +1257,7 @@ def code_deparse(
|
1257 | 1257 |
|
1258 | 1258 | assert iscode(co)
|
1259 | 1259 |
|
| 1260 | + |
1260 | 1261 | if version is None:
|
1261 | 1262 | version = PYTHON_VERSION_TRIPLE
|
1262 | 1263 |
|
@@ -1325,30 +1326,25 @@ def code_deparse(
|
1325 | 1326 |
|
1326 | 1327 | assert not nonlocals
|
1327 | 1328 |
|
1328 |
| - if version >= (3, 0): |
1329 |
| - load_op = "LOAD_STR" |
1330 |
| - else: |
1331 |
| - load_op = "LOAD_CONST" |
1332 |
| - |
1333 | 1329 | # convert leading '__doc__ = "..." into doc string
|
1334 | 1330 | try:
|
1335 | 1331 | stmts = deparsed.ast
|
1336 |
| - first_stmt = stmts[0][0] |
1337 |
| - if version >= 3.6: |
| 1332 | + first_stmt = stmts[0] |
| 1333 | + if version >= (3, 6): |
1338 | 1334 | if first_stmt[0] == "SETUP_ANNOTATIONS":
|
1339 | 1335 | del stmts[0]
|
1340 | 1336 | assert stmts[0] == "sstmt"
|
1341 | 1337 | # Nuke sstmt
|
1342 | 1338 | first_stmt = stmts[0][0]
|
1343 | 1339 | pass
|
1344 | 1340 | pass
|
1345 |
| - if first_stmt == ASSIGN_DOC_STRING(co.co_consts[0], load_op): |
| 1341 | + if first_stmt == "docstring": |
1346 | 1342 | print_docstring(deparsed, "", co.co_consts[0])
|
1347 | 1343 | del stmts[0]
|
1348 | 1344 | if stmts[-1] == RETURN_NONE:
|
1349 | 1345 | stmts.pop() # remove last node
|
1350 | 1346 | # todo: if empty, add 'pass'
|
1351 |
| - except: |
| 1347 | + except Exception: |
1352 | 1348 | pass
|
1353 | 1349 |
|
1354 | 1350 | deparsed.FUTURE_UNICODE_LITERALS = (
|
|
0 commit comments