Sync with decompyle3

This commit is contained in:
rocky
2024-02-17 20:14:30 -05:00
parent 0a08b8d3fc
commit 8c3143ce4c

View File

@@ -134,7 +134,7 @@ from io import StringIO
from typing import Optional from typing import Optional
from spark_parser import GenericASTTraversal from spark_parser import GenericASTTraversal
from xdis import COMPILER_FLAG_BIT, iscode from xdis import COMPILER_FLAG_BIT, IS_PYPY, iscode
from xdis.version_info import PYTHON_VERSION_TRIPLE from xdis.version_info import PYTHON_VERSION_TRIPLE
from uncompyle6.parser import get_python_parser, parse from uncompyle6.parser import get_python_parser, parse
@@ -149,6 +149,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,
@@ -189,8 +190,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 = {
@@ -210,7 +209,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.
""" """
@@ -267,27 +266,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
@@ -312,10 +316,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