You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Merge branch 'master' into python-3.3-to-3.5
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#!/bin/bash
|
||||
PYTHON_VERSION=3.7.13
|
||||
PYTHON_VERSION=3.7.14
|
||||
|
||||
function checkout_version {
|
||||
local repo=$1
|
||||
|
@@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2019-2020 by Rocky Bernstein
|
||||
# Copyright (c) 2019-2020, 2022 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
|
||||
@@ -24,6 +24,7 @@ from uncompyle6.semantics.consts import (
|
||||
|
||||
from uncompyle6.semantics.helper import flatten_list, gen_function_parens_adjust
|
||||
|
||||
|
||||
#######################
|
||||
# Python 3.5+ Changes #
|
||||
#######################
|
||||
@@ -34,14 +35,14 @@ def customize_for_version35(self, version):
|
||||
# nested await expressions like:
|
||||
# return await (await bar())
|
||||
# need parenthesis.
|
||||
"await_expr": ("await %p", (0, PRECEDENCE["await_expr"]-1)),
|
||||
"await_expr": ("await %p", (0, PRECEDENCE["await_expr"] - 1)),
|
||||
|
||||
"await_stmt": ("%|%c\n", 0),
|
||||
"async_for_stmt": (
|
||||
"%|async for %c in %c:\n%+%|%c%-\n\n",
|
||||
(9, "store"),
|
||||
(1, "expr"),
|
||||
(25, "for_block"),
|
||||
(25, ("for_block", "pass")),
|
||||
),
|
||||
"async_forelse_stmt": (
|
||||
"%|async for %c in %c:\n%+%c%-%|else:\n%+%c%-\n\n",
|
||||
@@ -65,6 +66,7 @@ def customize_for_version35(self, version):
|
||||
# "unmapexpr": ( "{**%c}", 0), # done by n_unmapexpr
|
||||
}
|
||||
)
|
||||
|
||||
# fmt: on
|
||||
|
||||
def async_call(node):
|
||||
@@ -97,6 +99,8 @@ def customize_for_version35(self, version):
|
||||
if lastnodetype.startswith("BUILD_LIST"):
|
||||
self.write("[")
|
||||
endchar = "]"
|
||||
else:
|
||||
endchar = ""
|
||||
|
||||
flat_elems = flatten_list(node)
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2019-2021 by Rocky Bernstein
|
||||
# Copyright (c) 2019-2022 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
|
||||
@@ -61,7 +61,8 @@ def customize_for_version36(self, version):
|
||||
"%|async for %c in %c:\n%+%c%-\n\n",
|
||||
(9, "store"),
|
||||
(1, "expr"),
|
||||
(-9, "for_block"), # Count from end, since COME_FROM shifts things in the forward direction
|
||||
# Count from end, since COME_FROM shifts things in the forward direction
|
||||
(-9, ("for_block", "pass")),
|
||||
),
|
||||
"async_forelse_stmt36": (
|
||||
"%|async for %c in %c:\n%+%c%-%|else:\n%+%c%-\n\n",
|
||||
@@ -395,7 +396,7 @@ def customize_for_version36(self, version):
|
||||
|
||||
def call36_tuple(node):
|
||||
"""
|
||||
A tuple used in a call, these are like normal tuples but they
|
||||
A tuple used in a call; these are like normal tuples, but they
|
||||
don't have the enclosing parenthesis.
|
||||
"""
|
||||
assert node == "tuple"
|
||||
@@ -670,7 +671,7 @@ def customize_for_version36(self, version):
|
||||
else:
|
||||
# {{ and }} in Python source-code format strings mean
|
||||
# { and } respectively. But only when *not* part of a
|
||||
# formatted value. However in the LOAD_STR
|
||||
# formatted value. However, in the LOAD_STR
|
||||
# bytecode, the escaping of the braces has been
|
||||
# removed. So we need to put back the braces escaping in
|
||||
# reconstructing the source.
|
||||
|
@@ -26,6 +26,7 @@ from uncompyle6.semantics.helper import flatten_list
|
||||
|
||||
FSTRING_CONVERSION_MAP = {1: "!s", 2: "!r", 3: "!a", "X": ":X"}
|
||||
|
||||
|
||||
#######################
|
||||
def customize_for_version37(self, version):
|
||||
########################
|
||||
@@ -41,9 +42,9 @@ def customize_for_version37(self, version):
|
||||
PRECEDENCE["call_ex_kw4"] = 1
|
||||
PRECEDENCE["call_kw"] = 0
|
||||
PRECEDENCE["call_kw36"] = 1
|
||||
PRECEDENCE["formatted_value1"] = 38 # f"...". This has to be below "named_expr" to make
|
||||
# f'{(x := 10)}' preserve parenthesis
|
||||
PRECEDENCE["formatted_value2"] = 38 # See above
|
||||
PRECEDENCE["formatted_value1"] = 38 # f"...". This has to be below "named_expr" to make
|
||||
# f'{(x := 10)}' preserve parenthesis
|
||||
PRECEDENCE["formatted_value2"] = 38 # See above
|
||||
PRECEDENCE["if_exp_37a"] = 28
|
||||
PRECEDENCE["if_exp_37b"] = 28
|
||||
PRECEDENCE["dict_unpack"] = 0 # **{...}
|
||||
@@ -68,7 +69,7 @@ def customize_for_version37(self, version):
|
||||
"%|async for %c in %c:\n%+%c%-\n\n",
|
||||
(8, "store"),
|
||||
(1, "expr"),
|
||||
(17, "for_block"),
|
||||
(17, ("for_block", "pass")),
|
||||
),
|
||||
"async_with_stmt": ("%|async with %c:\n%+%c%-", (0, "expr"), 3),
|
||||
"async_with_as_stmt": (
|
||||
@@ -85,9 +86,11 @@ def customize_for_version37(self, version):
|
||||
(-2, "else_suite"),
|
||||
),
|
||||
"attribute37": ("%c.%[1]{pattr}", (0, "expr")),
|
||||
"attributes37": ("%[0]{pattr} import %c",
|
||||
(0, "IMPORT_NAME_ATTR"),
|
||||
(1, "IMPORT_FROM")),
|
||||
"attributes37": (
|
||||
"%[0]{pattr} import %c",
|
||||
(0, "IMPORT_NAME_ATTR"),
|
||||
(1, "IMPORT_FROM")
|
||||
),
|
||||
|
||||
# nested await expressions like:
|
||||
# return await (await bar())
|
||||
@@ -131,8 +134,10 @@ def customize_for_version37(self, version):
|
||||
(0, PRECEDENCE["compare"] - 1),
|
||||
(6, PRECEDENCE["compare"] - 1),
|
||||
),
|
||||
'if_exp37': ( '%p if %c else %c',
|
||||
(1, 'expr', 27), 0, 3 ),
|
||||
'if_exp37': (
|
||||
'%p if %c else %c',
|
||||
(1, 'expr', 27), 0, 3
|
||||
),
|
||||
|
||||
"except_return": ("%|except:\n%+%c%-", 3),
|
||||
"if_exp_37a": (
|
||||
@@ -148,7 +153,9 @@ def customize_for_version37(self, version):
|
||||
(5, "expr", 27),
|
||||
),
|
||||
"ifstmtl": ("%|if %c:\n%+%c%-", (0, "testexpr"), (1, "_ifstmts_jumpl")),
|
||||
'import_as37': ( '%|import %c as %c\n', 2, -2),
|
||||
'import_as37': (
|
||||
"%|import %c as %c\n", 2, -2
|
||||
),
|
||||
"import_from37": ("%|from %[2]{pattr} import %c\n", (3, "importlist37")),
|
||||
"import_from_as37": (
|
||||
"%|from %c as %c\n",
|
||||
@@ -256,6 +263,8 @@ def customize_for_version37(self, version):
|
||||
if lastnodetype.startswith("BUILD_LIST"):
|
||||
self.write("[")
|
||||
endchar = "]"
|
||||
else:
|
||||
endchar = ""
|
||||
|
||||
flat_elems = flatten_list(node)
|
||||
|
||||
|
@@ -36,7 +36,7 @@ def customize_for_version38(self, version):
|
||||
"%|async for %c in %c:\n%+%c%-%-\n\n",
|
||||
(2, "store"),
|
||||
(0, "expr"),
|
||||
(3, "for_block"),
|
||||
(3, ("for_block", "pass")),
|
||||
),
|
||||
"async_forelse_stmt38": (
|
||||
"%|async for %c in %c:\n%+%c%-%|else:\n%+%c%-\n\n",
|
||||
|
@@ -133,51 +133,34 @@ import sys
|
||||
|
||||
IS_PYPY = "__pypy__" in sys.builtin_module_names
|
||||
|
||||
from xdis import iscode, COMPILER_FLAG_BIT
|
||||
from spark_parser import GenericASTTraversal
|
||||
from xdis import COMPILER_FLAG_BIT, iscode
|
||||
from xdis.version_info import PYTHON_VERSION_TRIPLE
|
||||
|
||||
import uncompyle6.parser as python_parser
|
||||
from uncompyle6.parser import get_python_parser
|
||||
from uncompyle6.parsers.treenode import SyntaxTree
|
||||
from spark_parser import GenericASTTraversal
|
||||
from uncompyle6.scanner import Code, get_scanner
|
||||
import uncompyle6.parser as python_parser
|
||||
from uncompyle6.scanners.tok import Token
|
||||
from uncompyle6.semantics.check_ast import checker
|
||||
|
||||
from uncompyle6.semantics.consts import (ASSIGN_DOC_STRING, ASSIGN_TUPLE_PARAM,
|
||||
INDENT_PER_LEVEL, LINE_LENGTH, MAP,
|
||||
MAP_DIRECT, NAME_MODULE, NONE, PASS,
|
||||
PRECEDENCE, RETURN_LOCALS,
|
||||
RETURN_NONE, TAB, TABLE_R, escape)
|
||||
from uncompyle6.semantics.customize import customize_for_version
|
||||
from uncompyle6.semantics.gencomp import ComprehensionMixin
|
||||
from uncompyle6.semantics.helper import (
|
||||
find_globals_and_nonlocals,
|
||||
print_docstring
|
||||
)
|
||||
from uncompyle6.semantics.make_function1 import make_function1
|
||||
from uncompyle6.semantics.make_function2 import make_function2
|
||||
from uncompyle6.semantics.make_function3 import make_function3
|
||||
from uncompyle6.semantics.make_function36 import make_function36
|
||||
from uncompyle6.semantics.parser_error import ParserError
|
||||
from uncompyle6.semantics.customize import customize_for_version
|
||||
from uncompyle6.semantics.gencomp import ComprehensionMixin
|
||||
from uncompyle6.semantics.helper import (
|
||||
print_docstring,
|
||||
find_globals_and_nonlocals,
|
||||
)
|
||||
|
||||
from uncompyle6.scanners.tok import Token
|
||||
|
||||
from uncompyle6.semantics.n_actions import NonterminalActions
|
||||
from uncompyle6.semantics.transform import is_docstring, TreeTransform
|
||||
from uncompyle6.semantics.consts import (
|
||||
ASSIGN_DOC_STRING,
|
||||
ASSIGN_TUPLE_PARAM,
|
||||
INDENT_PER_LEVEL,
|
||||
LINE_LENGTH,
|
||||
MAP,
|
||||
MAP_DIRECT,
|
||||
NAME_MODULE,
|
||||
NONE,
|
||||
PASS,
|
||||
PRECEDENCE,
|
||||
RETURN_LOCALS,
|
||||
RETURN_NONE,
|
||||
TAB,
|
||||
TABLE_R,
|
||||
escape,
|
||||
)
|
||||
|
||||
|
||||
from uncompyle6.semantics.parser_error import ParserError
|
||||
from uncompyle6.semantics.transform import TreeTransform, is_docstring
|
||||
from uncompyle6.show import maybe_show_tree
|
||||
from uncompyle6.util import better_repr
|
||||
|
||||
@@ -541,7 +524,7 @@ class SourceWalker(GenericASTTraversal, NonterminalActions, ComprehensionMixin):
|
||||
make_function1(self, node, is_lambda, nested, code_node)
|
||||
elif self.version <= (2, 7):
|
||||
make_function2(self, node, is_lambda, nested, code_node)
|
||||
elif (3, 0) <= self.version <= (3, 5):
|
||||
elif (3, 0) <= self.version < (3, 6):
|
||||
make_function3(self, node, is_lambda, nested, code_node)
|
||||
elif self.version >= (3, 6):
|
||||
make_function36(self, node, is_lambda, nested, code_node)
|
||||
|
@@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2019-2021 by Rocky Bernstein
|
||||
# Copyright (c) 2019-2022 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
|
||||
@@ -432,7 +432,7 @@ class TreeTransform(GenericASTTraversal, object):
|
||||
if sstmt[0] == "ann_assign":
|
||||
sstmt[0] = ann_assign_init
|
||||
else:
|
||||
sstmt[0][0] = ann_assing_init
|
||||
sstmt[0][0] = ann_assign_init
|
||||
sstmt[0].transformed_by = "n_stmts"
|
||||
pass
|
||||
pass
|
||||
|
Reference in New Issue
Block a user