Merge branch 'python-3.0-to-3.2' into python-2.4-to-2.7

This commit is contained in:
rocky
2024-02-24 07:23:46 -05:00
4 changed files with 40 additions and 50 deletions

View File

@@ -645,16 +645,6 @@ def get_scanner(version, is_pypy=False, show_asm=None):
return scanner return scanner
def prefer_double_quote(string):
"""
Prefer a double quoted string over a
single quoted string when possible
"""
if string.find("'") == -1:
return '"%s"' % string
return repr(string)
if __name__ == "__main__": if __name__ == "__main__":
import inspect import inspect

View File

@@ -41,7 +41,7 @@ from xdis import Instruction, instruction_size, iscode
from xdis.bytecode import _get_const_info from xdis.bytecode import _get_const_info
from xdis.opcodes.opcode_3x import parse_fn_counts_30_35 from xdis.opcodes.opcode_3x import parse_fn_counts_30_35
from uncompyle6.scanner import CONST_COLLECTIONS, Scanner, prefer_double_quote from uncompyle6.scanner import CONST_COLLECTIONS, Scanner
from uncompyle6.scanners.tok import Token from uncompyle6.scanners.tok import Token
from uncompyle6.util import get_code_name from uncompyle6.util import get_code_name
@@ -597,7 +597,6 @@ class Scanner3(Scanner):
pattr = "<code_object " + const.co_name + ">" pattr = "<code_object " + const.co_name + ">"
elif isinstance(const, str) or isinstance(const, unicode): elif isinstance(const, str) or isinstance(const, unicode):
opname = "LOAD_STR" opname = "LOAD_STR"
pattr = prefer_double_quote(inst.argval)
else: else:
if isinstance(inst.arg, int) and inst.arg < len(co.co_consts): if isinstance(inst.arg, int) and inst.arg < len(co.co_consts):
argval, _ = _get_const_info(inst.arg, co.co_consts) argval, _ = _get_const_info(inst.arg, co.co_consts)

View File

@@ -38,7 +38,7 @@ import xdis.opcodes.opcode_37 as op3
from xdis import Instruction, instruction_size, iscode from xdis import Instruction, instruction_size, iscode
from xdis.bytecode import _get_const_info from xdis.bytecode import _get_const_info
from uncompyle6.scanner import Scanner, Token, prefer_double_quote from uncompyle6.scanner import Scanner, Token
globals().update(op3.opmap) globals().update(op3.opmap)
@@ -290,20 +290,22 @@ class Scanner37Base(Scanner):
# but the operator and operand properties come from the other # but the operator and operand properties come from the other
# instruction # instruction
self.insts[i] = Instruction( self.insts[i] = Instruction(
jump_inst.opname, opcode=jump_inst.opcode,
jump_inst.opcode, opname=jump_inst.opname,
jump_inst.optype, arg=jump_inst.arg,
jump_inst.inst_size, argval=jump_inst.argval,
jump_inst.arg, argrepr=jump_inst.argrepr,
jump_inst.argval, offset=inst.offset,
jump_inst.argrepr, starts_line=inst.starts_line,
jump_inst.has_arg, is_jump_target=inst.is_jump_target,
inst.offset, positions=None,
inst.starts_line, optype=jump_inst.optype,
inst.is_jump_target, has_arg=jump_inst.has_arg,
inst.has_extended_arg, inst_size=jump_inst.inst_size,
None, has_extended_arg=inst.has_extended_arg,
None, fallthrough=False,
tos_str=None,
start_offset=None,
) )
# Get jump targets # Get jump targets
@@ -383,7 +385,6 @@ class Scanner37Base(Scanner):
pattr = "<code_object " + const.co_name + ">" pattr = "<code_object " + const.co_name + ">"
elif isinstance(const, str): elif isinstance(const, str):
opname = "LOAD_STR" opname = "LOAD_STR"
pattr = prefer_double_quote(inst.argval)
else: else:
if isinstance(inst.arg, int) and inst.arg < len(co.co_consts): if isinstance(inst.arg, int) and inst.arg < len(co.co_consts):
argval, _ = _get_const_info(inst.arg, co.co_consts) argval, _ = _get_const_info(inst.arg, co.co_consts)
@@ -935,7 +936,7 @@ class Scanner37Base(Scanner):
if __name__ == "__main__": if __name__ == "__main__":
from xdis.version_info import PYTHON_VERSION_TRIPLE, version_tuple_to_str from xdis.version_info import PYTHON_VERSION_TRIPLE, version_tuple_to_str
if PYTHON_VERSION_TRIPLE[:2] == (3, 7): if (3, 7) <= PYTHON_VERSION_TRIPLE[:2] < (3, 9):
import inspect import inspect
co = inspect.currentframe().f_code # type: ignore co = inspect.currentframe().f_code # type: ignore

View File

@@ -148,6 +148,7 @@ from uncompyle6.semantics.consts import (
MAP, MAP,
MAP_DIRECT, MAP_DIRECT,
NAME_MODULE, NAME_MODULE,
NO_PARENTHESIS_EVER,
NONE, NONE,
PASS, PASS,
PRECEDENCE, PRECEDENCE,
@@ -191,8 +192,6 @@ PARSER_DEFAULT_DEBUG = {
"dups": False, "dups": False,
} }
IS_PYPY = "__pypy__" in sys.builtin_module_names
TREE_DEFAULT_DEBUG = {"before": False, "after": False} TREE_DEFAULT_DEBUG = {"before": False, "after": False}
DEFAULT_DEBUG_OPTS = { DEFAULT_DEBUG_OPTS = {
@@ -212,7 +211,7 @@ class SourceWalkerError(Exception):
class SourceWalker(GenericASTTraversal, NonterminalActions, ComprehensionMixin): class SourceWalker(GenericASTTraversal, NonterminalActions, ComprehensionMixin):
""" """
Class to traverses a Parse Tree of the bytecode instruction built from parsing to Class to traverse a Parse Tree of the bytecode instruction built from parsing to
produce some sort of source text. produce some sort of source text.
The Parse tree may be turned an Abstract Syntax tree as an intermediate step. The Parse tree may be turned an Abstract Syntax tree as an intermediate step.
""" """
@@ -269,27 +268,32 @@ class SourceWalker(GenericASTTraversal, NonterminalActions, ComprehensionMixin):
is_pypy=is_pypy, is_pypy=is_pypy,
) )
self.ast_errors = []
self.currentclass = None
self.classes = []
self.debug_parser = dict(debug_parser)
self.line_number = 1
self.linemap = {}
self.params = params
self.param_stack = []
self.ERROR = None self.ERROR = None
self.prec = 100 self.ast_errors = []
self.return_none = False self.classes = []
self.mod_globs = set() self.compile_mode = compile_mode
self.showast = showast self.currentclass = None
self.pending_newlines = 0 self.debug_parser = dict(debug_parser)
self.is_pypy = is_pypy
self.linemap = {}
self.line_number = 1
self.linestarts = linestarts self.linestarts = linestarts
self.mod_globs = set()
self.name = None
self.offset2inst_index = scanner.offset2inst_index
self.param_stack = []
self.params = params
self.pending_newlines = 0
self.prec = NO_PARENTHESIS_EVER
self.return_none = False
self.showast = showast
self.version = version
self.treeTransform = TreeTransform(version=self.version, show_ast=showast) self.treeTransform = TreeTransform(version=self.version, show_ast=showast)
# FIXME: have p.insts update in a better way # FIXME: have p.insts update in a better way
# modularity is broken here # modularity is broken here
self.insts = scanner.insts self.insts = scanner.insts
self.offset2inst_index = scanner.offset2inst_index
# Initialize p_lambda on demand # Initialize p_lambda on demand
self.p_lambda = None self.p_lambda = None
@@ -314,10 +318,6 @@ class SourceWalker(GenericASTTraversal, NonterminalActions, ComprehensionMixin):
# An example is: # An example is:
# __module__ = __name__ # __module__ = __name__
self.hide_internal = True self.hide_internal = True
self.compile_mode = compile_mode
self.name = None
self.version = version
self.is_pypy = is_pypy
customize_for_version(self, is_pypy, version) customize_for_version(self, is_pypy, version)
return return