Skip to content

Commit

Permalink
Python 2.5 try/except reduce fix
Browse files Browse the repository at this point in the history
Start getting aligner up to date
  • Loading branch information
rocky committed Jul 12, 2024
1 parent efbd657 commit cb2b90a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
2 changes: 1 addition & 1 deletion uncompyle6/parsers/reducecheck/tryexcept.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright (c) 2020, 2022, 2024 Rocky Bernstein


def tryexcept(self, lhs, n: int, rule, ast, tokens, first: int, last: int):
def tryexcept(self, lhs, n, rule, ast, tokens, first, last):
come_from_except = ast[-1]
if rule == (
"try_except",
Expand Down
1 change: 1 addition & 0 deletions uncompyle6/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"""

from abc import ABC
>>>>>>> Stashed changes
from array import array
from collections import namedtuple
from types import ModuleType
Expand Down
2 changes: 1 addition & 1 deletion uncompyle6/scanners/scanner3.py
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ def ingest(
names=co.co_names,
constants=co.co_consts,
cells=bytecode._cell_names,
linestarts=bytecode._linestarts,
line_starts=bytecode._linestarts,
asm_format="extended",
)

Expand Down
26 changes: 15 additions & 11 deletions uncompyle6/semantics/aligner.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2018, 2022-2023 by Rocky Bernstein
# Copyright (c) 2018, 2022-2024 by Rocky Bernstein
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Expand All @@ -18,11 +18,14 @@
from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
from xdis import iscode

from xdis.version_info import IS_PYPY
from xdis.version_info import IS_PYPY, PYTHON_VERSION_TRIPLE

from uncompyle6.scanner import get_scanner
from uncompyle6.semantics.consts import ASSIGN_DOC_STRING

from uncompyle6.semantics.pysource import (
ASSIGN_DOC_STRING,
RETURN_NONE,
TREE_DEFAULT_DEBUG,
SourceWalker,
SourceWalkerError,
find_globals_and_nonlocals
Expand All @@ -38,7 +41,7 @@ def __init__(
version,
out,
scanner,
showast=False,
showast=TREE_DEFAULT_DEBUG,
debug_parser=PARSER_DEFAULT_DEBUG,
compile_mode="exec",
is_pypy=False,
Expand All @@ -48,6 +51,7 @@ def __init__(
)
self.desired_line_number = 0
self.current_line_number = 0
self.showast = showast

def println(self, *data):
if data and not (len(data) == 1 and data[0] == ""):
Expand Down Expand Up @@ -113,12 +117,12 @@ def default(self, node):
key = key[i]
pass

if key.type in table:
self.template_engine(table[key.type], node)
if key.kind in table:
self.template_engine(table[key.kind], node)
self.prune()


DEFAULT_DEBUG_OPTS = {"asm": False, "tree": False, "grammar": False}
DEFAULT_DEBUG_OPTS = {"asm": False, "tree": TREE_DEFAULT_DEBUG, "grammar": False}


def code_deparse_align(
Expand All @@ -137,7 +141,7 @@ def code_deparse_align(
assert iscode(co)

if version is None:
version = float(sys.version[0:3])
version = PYTHON_VERSION_TRIPLE
if is_pypy is None:
is_pypy = IS_PYPY

Expand All @@ -156,11 +160,11 @@ def code_deparse_align(
debug_parser["errorstack"] = True

# Build a parse tree from tokenized and massaged disassembly.
show_ast = debug_opts.get("ast", None)
show_ast = debug_opts.get("ast", TREE_DEFAULT_DEBUG)
deparsed = AligningWalker(
version,
scanner,
out,
scanner,
showast=show_ast,
debug_parser=debug_parser,
compile_mode=compile_mode,
Expand Down Expand Up @@ -210,4 +214,4 @@ def deparse_test(co):
print(deparsed.text)
return

deparse_test(deparse_test.__code__)
deparse_test(deparse_test.func_code)
2 changes: 1 addition & 1 deletion uncompyle6/semantics/linemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,4 @@ def deparse_test(co):
# assert linemap == linemap2
return

deparse_test(deparse_test.__code__)
deparse_test(deparse_test.func_code)

0 comments on commit cb2b90a

Please sign in to comment.