Skip to content

Commit be82523

Browse files
committed
2.6 custom tryelse code is no longer needed?
If it turns out to be needed, add it back in a better way.
1 parent 4394d46 commit be82523

File tree

2 files changed

+22
-51
lines changed

2 files changed

+22
-51
lines changed

test/test_pyenvlib.py

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22
# emacs-mode: -*-python-*-
33
"""
4-
test_pyenvlib -- uncompyle and verify Python libraries
4+
test_pyenvlib -- decompile and verify Python libraries
55
66
Usage-Examples:
77
@@ -22,12 +22,17 @@
2222

2323
from __future__ import print_function
2424

25-
import os, time, re, shutil, sys
25+
import os
26+
import re
27+
import shutil
28+
import sys
29+
import time
2630
from fnmatch import fnmatch
2731

28-
from uncompyle6 import main
2932
import xdis.magics as magics
3033

34+
from uncompyle6 import main
35+
3136
# ----- configure this for your needs
3237

3338
python_versions = [v for v in magics.python_versions if re.match("^[0-9.]+$", v)]
@@ -82,6 +87,7 @@
8287
if vers == "native":
8388
short_vers = os.path.basename(sys.path[-1])
8489
from xdis.version_info import PYTHON_VERSION_TRIPLE, version_tuple_to_str
90+
8591
if PYTHON_VERSION_TRIPLE > (3, 0):
8692
version = version_tuple_to_str(end=2)
8793
PYC = f"*.cpython-{version}.pyc"
@@ -133,8 +139,17 @@ def visitor(files, dirname, names):
133139
pass
134140

135141
if len(files) > max_files:
136-
files = [file for file in files if not "site-packages" in file and (file.endswith(".pyo") or file.endswith(".pyc"))]
137-
files = [file for file in files if not "test" in file and (file.endswith(".pyo") or file.endswith(".pyc"))]
142+
files = [
143+
file
144+
for file in files
145+
if not "site-packages" in file
146+
and (file.endswith(".pyo") or file.endswith(".pyc"))
147+
]
148+
files = [
149+
file
150+
for file in files
151+
if not "test" in file and (file.endswith(".pyo") or file.endswith(".pyc"))
152+
]
138153
if len(files) > max_files:
139154
# print("Number of files %d - truncating to last 200" % len(files))
140155
print(
@@ -151,7 +166,8 @@ def visitor(files, dirname, names):
151166

152167

153168
if __name__ == "__main__":
154-
import getopt, sys
169+
import getopt
170+
import sys
155171

156172
do_coverage = do_verify = False
157173
test_dirs = []

uncompyle6/parsers/parse26.py

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -493,51 +493,6 @@ def reduce_is_invalid(self, rule, ast, tokens, first, last):
493493
return tokens[last - 3].kind not in frozenset(
494494
("JUMP_FORWARD", "RETURN_VALUE")
495495
) or (tokens[last - 3] == "JUMP_FORWARD" and tokens[last - 3].attr != 2)
496-
elif lhs == "tryelsestmt":
497-
# We need to distinguish "try_except" from "tryelsestmt"; we do that
498-
# by making sure that the jump before the except handler jumps to
499-
# code somewhere before the end of the construct.
500-
# This AST method is slower, but the token-only based approach
501-
# didn't work as it failed with a "try" embedded inside a "try/else"
502-
# since we can't detect COME_FROM boundaries.
503-
504-
if ast[3] == "except_handler":
505-
except_handler = ast[3]
506-
if except_handler[0] == "JUMP_FORWARD":
507-
else_start = int(except_handler[0].pattr)
508-
if last == len(tokens):
509-
last -= 1
510-
if tokens[last] == "COME_FROM" and isinstance:
511-
last_offset = int(tokens[last].offset.split("_")[0])
512-
return else_start >= last_offset
513-
514-
# The above test apparently isn't good enough, so we have additional
515-
# checks distinguish "try_except" from "tryelsestmt". we do that
516-
# by checking the jump before the "END_FINALLY".
517-
# If we have:
518-
# insn
519-
# POP_TOP
520-
# END_FINALLY
521-
# COME_FROM
522-
# then insn is neither a JUMP_FORWARD nor RETURN_VALUE,
523-
# or if it is JUMP_FORWARD, then it can't be a JUMP_FORWARD to right after
524-
# COME_FROM
525-
if last == len(tokens):
526-
last -= 1
527-
while tokens[last - 1] == "COME_FROM" and tokens[last - 2] == "COME_FROM":
528-
last -= 1
529-
if tokens[last] == "COME_FROM" and tokens[last - 1] == "COME_FROM":
530-
last -= 1
531-
if (
532-
tokens[last] == "COME_FROM"
533-
and tokens[last - 1] == "END_FINALLY"
534-
and tokens[last - 2] == "POP_TOP"
535-
):
536-
# A jump of 2 is a jump around POP_TOP, END_FINALLY which
537-
# would indicate try/else rather than try
538-
return tokens[last - 3].kind in frozenset(
539-
("JUMP_FORWARD", "RETURN_VALUE")
540-
) and (tokens[last - 3] != "JUMP_FORWARD" or tokens[last - 3].attr == 2)
541496

542497
return False
543498

0 commit comments

Comments
 (0)