From 4b2a2e218ab9f4e7e1b16ef9d280827c271e1da0 Mon Sep 17 00:00:00 2001 From: rocky Date: Fri, 16 Sep 2022 15:38:13 -0400 Subject: [PATCH] Misc lint stuff from pycharm... that has been applied to decompyle3 already --- requirements.txt | 5 +++++ setup.py | 7 +++---- uncompyle6/bin/pydisassemble.py | 2 +- uncompyle6/{disas.py => code_fns.py} | 0 uncompyle6/main.py | 2 +- uncompyle6/scanner.py | 4 ++-- uncompyle6/scanners/pypy37.py | 1 + uncompyle6/scanners/pypy38.py | 1 + uncompyle6/scanners/scanner37.py | 4 ++-- uncompyle6/scanners/scanner37base.py | 16 ++++++++++------ uncompyle6/scanners/scanner38.py | 4 ++-- uncompyle6/scanners/tok.py | 5 +++-- 12 files changed, 31 insertions(+), 20 deletions(-) rename uncompyle6/{disas.py => code_fns.py} (100%) diff --git a/requirements.txt b/requirements.txt index 5b1e7b65..40a86898 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,8 @@ hypothesis==2.0.0 pytest -e . + +Click~=7.0 +xdis>=6.0.4 +configobj~=5.0.6 +setuptools~=65.3.0 diff --git a/setup.py b/setup.py index c88e7362..05b1b788 100755 --- a/setup.py +++ b/setup.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +import setuptools import sys """Setup script for the 'uncompyle6' distribution.""" @@ -39,9 +40,7 @@ from __pkginfo__ import ( zip_safe, ) -from setuptools import setup, find_packages - -setup( +setuptools.setup( author=author, author_email=author_email, classifiers=classifiers, @@ -52,7 +51,7 @@ setup( long_description=long_description, long_description_content_type="text/x-rst", name=modname, - packages=find_packages(), + packages=setuptools.find_packages(), py_modules=py_modules, test_suite="nose.collector", url=web, diff --git a/uncompyle6/bin/pydisassemble.py b/uncompyle6/bin/pydisassemble.py index 9f43f7af..219158fc 100755 --- a/uncompyle6/bin/pydisassemble.py +++ b/uncompyle6/bin/pydisassemble.py @@ -6,7 +6,7 @@ from __future__ import print_function import sys, os, getopt -from uncompyle6.disas import disassemble_file +from uncompyle6.code_fns import disassemble_file from uncompyle6.version import __version__ program, ext = os.path.splitext(os.path.basename(__file__)) diff --git a/uncompyle6/disas.py b/uncompyle6/code_fns.py similarity index 100% rename from uncompyle6/disas.py rename to uncompyle6/code_fns.py diff --git a/uncompyle6/main.py b/uncompyle6/main.py index 1cdd2657..edf29096 100644 --- a/uncompyle6/main.py +++ b/uncompyle6/main.py @@ -18,7 +18,7 @@ import datetime, py_compile, os, sys from xdis import iscode from xdis.version_info import IS_PYPY, PYTHON_VERSION_TRIPLE, version_tuple_to_str -from uncompyle6.disas import check_object_path +from uncompyle6.code_fns import check_object_path from uncompyle6.semantics import pysource from uncompyle6.semantics.pysource import PARSER_DEFAULT_DEBUG from uncompyle6.parser import ParserError diff --git a/uncompyle6/scanner.py b/uncompyle6/scanner.py index d4fcfc4b..6452dae4 100644 --- a/uncompyle6/scanner.py +++ b/uncompyle6/scanner.py @@ -133,9 +133,9 @@ class Scanner(object): assert count <= i if collection_type == "CONST_DICT": - # constant dictonaries work via BUILD_CONST_KEY_MAP and + # constant dictionaries work via BUILD_CONST_KEY_MAP and # handle the values() like sets and lists. - # However the keys() are an LOAD_CONST of the keys. + # However, the keys() are an LOAD_CONST of the keys. # adjust offset to account for this count += 1 diff --git a/uncompyle6/scanners/pypy37.py b/uncompyle6/scanners/pypy37.py index 6856c839..eac8b2e3 100644 --- a/uncompyle6/scanners/pypy37.py +++ b/uncompyle6/scanners/pypy37.py @@ -13,6 +13,7 @@ from xdis.opcodes import opcode_37pypy as opc # is this right? JUMP_OPs = opc.JUMP_OPS + # We base this off of 3.7 class ScannerPyPy37(scan.Scanner37): def __init__(self, show_asm): diff --git a/uncompyle6/scanners/pypy38.py b/uncompyle6/scanners/pypy38.py index f32c1bbd..8f22e397 100644 --- a/uncompyle6/scanners/pypy38.py +++ b/uncompyle6/scanners/pypy38.py @@ -13,6 +13,7 @@ from xdis.opcodes import opcode_38pypy as opc JUMP_OPs = opc.JUMP_OPS + # We base this off of 3.8 class ScannerPyPy38(scan.Scanner38): def __init__(self, show_asm): diff --git a/uncompyle6/scanners/scanner37.py b/uncompyle6/scanners/scanner37.py index e88a8a78..99517ee9 100644 --- a/uncompyle6/scanners/scanner37.py +++ b/uncompyle6/scanners/scanner37.py @@ -120,7 +120,7 @@ class Scanner37(Scanner37Base): return new_tokens def ingest( - self, co, classname=None, code_objects={}, show_asm=None + self, bytecode, classname=None, code_objects={}, show_asm=None ) -> Tuple[list, dict]: """ Create "tokens" the bytecode of an Python code object. Largely these @@ -141,7 +141,7 @@ class Scanner37(Scanner37Base): cause specific rules for the specific number of arguments they take. """ tokens, customize = Scanner37Base.ingest( - self, co, classname, code_objects, show_asm + self, bytecode, classname, code_objects, show_asm ) new_tokens = [] for i, t in enumerate(tokens): diff --git a/uncompyle6/scanners/scanner37base.py b/uncompyle6/scanners/scanner37base.py index 5dc63519..1c6c499b 100644 --- a/uncompyle6/scanners/scanner37base.py +++ b/uncompyle6/scanners/scanner37base.py @@ -47,14 +47,18 @@ import sys globals().update(op3.opmap) +CONST_COLLECTIONS = ("CONST_LIST", "CONST_SET", "CONST_DICT") + + class Scanner37Base(Scanner): - def __init__(self, version: Tuple[int], show_asm=None, debug="", is_pypy=False): + def __init__(self, version: Tuple[int, int], show_asm=None, debug="", is_pypy=False): super(Scanner37Base, self).__init__(version, show_asm, is_pypy) + self.offset2tok_index = None self.debug = debug self.is_pypy = is_pypy # Create opcode classification sets - # Note: super initilization above initializes self.opc + # Note: super initialization above initializes self.opc # Ops that start SETUP_ ... We will COME_FROM with these names # Some blocks and END_ statements. And they can start @@ -139,7 +143,7 @@ class Scanner37Base(Scanner): self.opc.POP_JUMP_IF_FALSE, ] ) - # Not really a set, but still clasification-like + # Not really a set, but still classification-like self.statement_opcode_sequences = [ (self.opc.POP_JUMP_IF_FALSE, self.opc.JUMP_FORWARD), (self.opc.POP_JUMP_IF_FALSE, self.opc.JUMP_ABSOLUTE), @@ -274,7 +278,7 @@ class Scanner37Base(Scanner): if inst.opname == "JUMP_FORWARD": jump_inst = self.insts[self.offset2inst_index[inst.argval]] if jump_inst.has_extended_arg and jump_inst.opname.startswith("JUMP"): - # Create comination of the jump-to instruction and + # Create a combination of the jump-to instruction and # this one. Keep the position information of this instruction, # but the operator and operand properties come from the other # instruction @@ -442,9 +446,9 @@ class Scanner37Base(Scanner): elif op == self.opc.JUMP_ABSOLUTE: # Refine JUMP_ABSOLUTE further in into: # - # * "JUMP_LOOP" - which are are used in loops. This is sometimes + # * "JUMP_LOOP" - which are used in loops. This is sometimes # found at the end of a looping construct - # * "BREAK_LOOP" - which are are used to break loops. + # * "BREAK_LOOP" - which are used to break loops. # * "CONTINUE" - jumps which may appear in a "continue" statement. # It is okay to confuse this with JUMP_LOOP. The # grammar should tolerate this. diff --git a/uncompyle6/scanners/scanner38.py b/uncompyle6/scanners/scanner38.py index 765daf2b..98fb090d 100644 --- a/uncompyle6/scanners/scanner38.py +++ b/uncompyle6/scanners/scanner38.py @@ -44,7 +44,7 @@ class Scanner38(Scanner37): pass def ingest( - self, co, classname=None, code_objects={}, show_asm=None + self, bytecode, classname=None, code_objects={}, show_asm=None ) -> Tuple[list, dict]: """ Create "tokens" the bytecode of an Python code object. Largely these @@ -65,7 +65,7 @@ class Scanner38(Scanner37): cause specific rules for the specific number of arguments they take. """ tokens, customize = super(Scanner38, self).ingest( - co, classname, code_objects, show_asm + bytecode, classname, code_objects, show_asm ) # Hacky way to detect loop ranges. diff --git a/uncompyle6/scanners/tok.py b/uncompyle6/scanners/tok.py index f98b6306..def45346 100644 --- a/uncompyle6/scanners/tok.py +++ b/uncompyle6/scanners/tok.py @@ -15,7 +15,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import re, sys +import re +import sys intern = sys.intern @@ -87,7 +88,7 @@ class Token: print(f"I don't know about Python version {e} yet.") try: version_tuple = tuple(int(i) for i in str(e)[1:-1].split(".")) - except: + except Exception: pass else: if version_tuple > (3, 9):