From ece788e09e07d1aed726dc175160df38bb47619e Mon Sep 17 00:00:00 2001 From: rocky Date: Sun, 11 Feb 2024 09:11:39 -0500 Subject: [PATCH] Merge hell --- uncompyle6/bin/uncompile.py | 13 +++++-------- uncompyle6/main.py | 17 ++++++++++------- uncompyle6/scanner.py | 7 +++---- uncompyle6/semantics/pysource.py | 15 +++++++++------ uncompyle6/semantics/transform.py | 3 +-- 5 files changed, 28 insertions(+), 27 deletions(-) diff --git a/uncompyle6/bin/uncompile.py b/uncompyle6/bin/uncompile.py index 80b15146..b11479e2 100755 --- a/uncompyle6/bin/uncompile.py +++ b/uncompyle6/bin/uncompile.py @@ -5,12 +5,10 @@ # by Rocky Bernstein # Copyright (c) 2000-2002 by hartmut Goebel # -from __future__ import print_function import os import sys import time -from typing import List import click from xdis.version_info import version_tuple_to_str @@ -31,7 +29,6 @@ def usage(): # Usage: # %s [OPTIONS]... [ FILE | DIR]... # %s [--help | -h | --V | --version] ->>>>>>> master # Examples: # %s foo.pyc bar.pyc # decompile foo.pyc, bar.pyc to stdout @@ -160,11 +157,11 @@ def main_bin( """ version_tuple = sys.version_info[0:2] - if version_tuple < (3, 7): + if not ((3, 3) <= version_tuple < (3, 6)): print( - f"Error: This version of the {program} runs from Python 3.7 or greater." - f"You need another branch of this code for Python before 3.7." - f""" \n\tYou have version: {version_tuple_to_str()}.""" + "Error: This version of the {program} runs from Python 3.3 to 3.6." + "You need another branch of this code for other Python versions." + " \n\tYou have version: %s." % version_tuple_to_str() ) sys.exit(-1) @@ -172,7 +169,7 @@ def main_bin( out_base = None out_base = None - source_paths: List[str] = [] + source_paths = [] timestamp = False timestampfmt = "# %Y.%m.%d %H:%M:%S %Z" pyc_paths = files diff --git a/uncompyle6/main.py b/uncompyle6/main.py index aaa6c71c..e970c344 100644 --- a/uncompyle6/main.py +++ b/uncompyle6/main.py @@ -258,7 +258,7 @@ def main( outfile=None, showasm=None, showast={}, - do_verify = None, + do_verify=None, showgrammar: bool = False, source_encoding=None, do_linemaps=False, @@ -358,10 +358,12 @@ def main( deparsed_object.f.close() if PYTHON_VERSION_TRIPLE[:2] != deparsed_object.version[:2]: sys.stdout.write( - f"\n# skipping running {deparsed_object.f.name}; it is" - f"{version_tuple_to_str(deparsed_object.version, end=2)}, " - "and we are " - f"{version_tuple_to_str(PYTHON_VERSION_TRIPLE, end=2)}\n" + "\n# skipping running %s; it is %s and we are %s" + % ( + deparsed_object.f.name, + version_tuple_to_str(deparsed_object.version, end=2), + version_tuple_to_str(PYTHON_VERSION_TRIPLE, end=2), + ) ) else: check_type = "syntax check" @@ -385,10 +387,11 @@ def main( if not valid: verify_failed_files += 1 sys.stderr.write( - f"\n# {check_type} failed on file {deparsed_object.f.name}\n" + "\n# %s failed on file %s\n" + % (check_type, deparsed_object.f.name) ) - # sys.stderr.write(f"Ran {deparsed_object.f.name}\n") + # sys.stderr.write("Ran %\n" % deparsed_object.f.name) pass tot_files += 1 except (ValueError, SyntaxError, ParserError, pysource.SourceWalkerError) as e: diff --git a/uncompyle6/scanner.py b/uncompyle6/scanner.py index 0b5faa28..0993006f 100644 --- a/uncompyle6/scanner.py +++ b/uncompyle6/scanner.py @@ -22,10 +22,8 @@ scanners, e.g. for Python 2.7 or 3.4. """ import sys - from array import array from collections import namedtuple -from types import ModuleType import xdis from xdis import ( @@ -629,11 +627,12 @@ def get_scanner(version, is_pypy=False, show_asm=None): # If version is a string, turn that into the corresponding float. if isinstance(version, str): if version not in canonic_python_version: - raise RuntimeError(f"Unknown Python version in xdis {version}") + raise RuntimeError("Unknown Python version in xdis %s" % version) canonic_version = canonic_python_version[version] if canonic_version not in CANONIC2VERSION: raise RuntimeError( - f"Unsupported Python version {version} (canonic {canonic_version})" + "Unsupported Python version %s (canonic %s)" + % (version, canonic_version) ) version = CANONIC2VERSION[canonic_version] diff --git a/uncompyle6/semantics/pysource.py b/uncompyle6/semantics/pysource.py index d5ace7f0..fc8614d4 100644 --- a/uncompyle6/semantics/pysource.py +++ b/uncompyle6/semantics/pysource.py @@ -131,7 +131,6 @@ Python. import sys from io import StringIO -from typing import Optional from spark_parser import GenericASTTraversal from xdis import COMPILER_FLAG_BIT, iscode @@ -808,9 +807,13 @@ class SourceWalker(GenericASTTraversal, NonterminalActions, ComprehensionMixin): node[index].kind, ) else: - assert node[tup[0]] in tup[1], ( - f"at {node.kind}[{tup[0]}], expected to be in '{tup[1]}' " - f"node; got '{node[tup[0]].kind}'" + assert ( + node[tup[0]] in tup[1] + ), "at %s[%d], expected to be in '%s' node; got '%s'" % ( + node.kind, + arg, + index[1], + node[index[0]].kind, ) else: @@ -1281,7 +1284,7 @@ class SourceWalker(GenericASTTraversal, NonterminalActions, ComprehensionMixin): def code_deparse( co, out=sys.stdout, - version: Optional[tuple] = None, + version=None, debug_opts=DEFAULT_DEBUG_OPTS, code_objects={}, compile_mode="exec", @@ -1289,7 +1292,7 @@ def code_deparse( walker=SourceWalker, start_offset: int = 0, stop_offset: int = -1, -) -> Optional[SourceWalker]: +): """ ingests and deparses a given code block 'co'. If version is None, we will use the current Python interpreter version. diff --git a/uncompyle6/semantics/transform.py b/uncompyle6/semantics/transform.py index 430f1e0f..b646071b 100644 --- a/uncompyle6/semantics/transform.py +++ b/uncompyle6/semantics/transform.py @@ -14,7 +14,6 @@ # along with this program. If not, see . from copy import copy -from typing import Optional from spark_parser import GenericASTTraversal, GenericASTTraversalPruningException @@ -73,7 +72,7 @@ class TreeTransform(GenericASTTraversal, object): self, version: tuple, is_pypy=False, - show_ast: Optional[dict] = None, + show_ast=None, ): self.version = version self.showast = show_ast