Merge branch 'python-3.3-to-3.5' into python-2.4

This commit is contained in:
rocky
2022-09-22 06:39:05 -04:00
7 changed files with 53 additions and 56 deletions

View File

@@ -1,5 +1,5 @@
#!/bin/bash #!/bin/bash
PYTHON_VERSION=3.7.13 PYTHON_VERSION=3.7.14
function checkout_version { function checkout_version {
local repo=$1 local repo=$1

View File

@@ -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 # 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 # 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 from uncompyle6.semantics.helper import flatten_list, gen_function_parens_adjust
####################### #######################
# Python 3.5+ Changes # # Python 3.5+ Changes #
####################### #######################
@@ -34,14 +35,14 @@ def customize_for_version35(self, version):
# nested await expressions like: # nested await expressions like:
# return await (await bar()) # return await (await bar())
# need parenthesis. # 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), "await_stmt": ("%|%c\n", 0),
"async_for_stmt": ( "async_for_stmt": (
"%|async for %c in %c:\n%+%|%c%-\n\n", "%|async for %c in %c:\n%+%|%c%-\n\n",
(9, "store"), (9, "store"),
(1, "expr"), (1, "expr"),
(25, "for_block"), (25, ("for_block", "pass")),
), ),
"async_forelse_stmt": ( "async_forelse_stmt": (
"%|async for %c in %c:\n%+%c%-%|else:\n%+%c%-\n\n", "%|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 # "unmapexpr": ( "{**%c}", 0), # done by n_unmapexpr
} }
) )
# fmt: on # fmt: on
def async_call(node): def async_call(node):
@@ -97,6 +99,8 @@ def customize_for_version35(self, version):
if lastnodetype.startswith("BUILD_LIST"): if lastnodetype.startswith("BUILD_LIST"):
self.write("[") self.write("[")
endchar = "]" endchar = "]"
else:
endchar = ""
flat_elems = flatten_list(node) flat_elems = flatten_list(node)

View File

@@ -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 # 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 # 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", "%|async for %c in %c:\n%+%c%-\n\n",
(9, "store"), (9, "store"),
(1, "expr"), (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_forelse_stmt36": (
"%|async for %c in %c:\n%+%c%-%|else:\n%+%c%-\n\n", "%|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): 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. don't have the enclosing parenthesis.
""" """
assert node == "tuple" assert node == "tuple"
@@ -670,7 +671,7 @@ def customize_for_version36(self, version):
else: else:
# {{ and }} in Python source-code format strings mean # {{ and }} in Python source-code format strings mean
# { and } respectively. But only when *not* part of a # { 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 # bytecode, the escaping of the braces has been
# removed. So we need to put back the braces escaping in # removed. So we need to put back the braces escaping in
# reconstructing the source. # reconstructing the source.

View File

@@ -26,6 +26,7 @@ from uncompyle6.semantics.helper import flatten_list
FSTRING_CONVERSION_MAP = {1: "!s", 2: "!r", 3: "!a", "X": ":X"} FSTRING_CONVERSION_MAP = {1: "!s", 2: "!r", 3: "!a", "X": ":X"}
####################### #######################
def customize_for_version37(self, version): def customize_for_version37(self, version):
######################## ########################
@@ -41,9 +42,9 @@ def customize_for_version37(self, version):
PRECEDENCE["call_ex_kw4"] = 1 PRECEDENCE["call_ex_kw4"] = 1
PRECEDENCE["call_kw"] = 0 PRECEDENCE["call_kw"] = 0
PRECEDENCE["call_kw36"] = 1 PRECEDENCE["call_kw36"] = 1
PRECEDENCE["formatted_value1"] = 38 # f"...". This has to be below "named_expr" to make PRECEDENCE["formatted_value1"] = 38 # f"...". This has to be below "named_expr" to make
# f'{(x := 10)}' preserve parenthesis # f'{(x := 10)}' preserve parenthesis
PRECEDENCE["formatted_value2"] = 38 # See above PRECEDENCE["formatted_value2"] = 38 # See above
PRECEDENCE["if_exp_37a"] = 28 PRECEDENCE["if_exp_37a"] = 28
PRECEDENCE["if_exp_37b"] = 28 PRECEDENCE["if_exp_37b"] = 28
PRECEDENCE["dict_unpack"] = 0 # **{...} PRECEDENCE["dict_unpack"] = 0 # **{...}
@@ -68,7 +69,7 @@ def customize_for_version37(self, version):
"%|async for %c in %c:\n%+%c%-\n\n", "%|async for %c in %c:\n%+%c%-\n\n",
(8, "store"), (8, "store"),
(1, "expr"), (1, "expr"),
(17, "for_block"), (17, ("for_block", "pass")),
), ),
"async_with_stmt": ("%|async with %c:\n%+%c%-", (0, "expr"), 3), "async_with_stmt": ("%|async with %c:\n%+%c%-", (0, "expr"), 3),
"async_with_as_stmt": ( "async_with_as_stmt": (
@@ -85,9 +86,11 @@ def customize_for_version37(self, version):
(-2, "else_suite"), (-2, "else_suite"),
), ),
"attribute37": ("%c.%[1]{pattr}", (0, "expr")), "attribute37": ("%c.%[1]{pattr}", (0, "expr")),
"attributes37": ("%[0]{pattr} import %c", "attributes37": (
(0, "IMPORT_NAME_ATTR"), "%[0]{pattr} import %c",
(1, "IMPORT_FROM")), (0, "IMPORT_NAME_ATTR"),
(1, "IMPORT_FROM")
),
# nested await expressions like: # nested await expressions like:
# return await (await bar()) # return await (await bar())
@@ -131,8 +134,10 @@ def customize_for_version37(self, version):
(0, PRECEDENCE["compare"] - 1), (0, PRECEDENCE["compare"] - 1),
(6, PRECEDENCE["compare"] - 1), (6, PRECEDENCE["compare"] - 1),
), ),
'if_exp37': ( '%p if %c else %c', 'if_exp37': (
(1, 'expr', 27), 0, 3 ), '%p if %c else %c',
(1, 'expr', 27), 0, 3
),
"except_return": ("%|except:\n%+%c%-", 3), "except_return": ("%|except:\n%+%c%-", 3),
"if_exp_37a": ( "if_exp_37a": (
@@ -148,7 +153,9 @@ def customize_for_version37(self, version):
(5, "expr", 27), (5, "expr", 27),
), ),
"ifstmtl": ("%|if %c:\n%+%c%-", (0, "testexpr"), (1, "_ifstmts_jumpl")), "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_from37": ("%|from %[2]{pattr} import %c\n", (3, "importlist37")),
"import_from_as37": ( "import_from_as37": (
"%|from %c as %c\n", "%|from %c as %c\n",
@@ -256,6 +263,8 @@ def customize_for_version37(self, version):
if lastnodetype.startswith("BUILD_LIST"): if lastnodetype.startswith("BUILD_LIST"):
self.write("[") self.write("[")
endchar = "]" endchar = "]"
else:
endchar = ""
flat_elems = flatten_list(node) flat_elems = flatten_list(node)

View File

@@ -36,7 +36,7 @@ def customize_for_version38(self, version):
"%|async for %c in %c:\n%+%c%-%-\n\n", "%|async for %c in %c:\n%+%c%-%-\n\n",
(2, "store"), (2, "store"),
(0, "expr"), (0, "expr"),
(3, "for_block"), (3, ("for_block", "pass")),
), ),
"async_forelse_stmt38": ( "async_forelse_stmt38": (
"%|async for %c in %c:\n%+%c%-%|else:\n%+%c%-\n\n", "%|async for %c in %c:\n%+%c%-%|else:\n%+%c%-\n\n",

View File

@@ -133,51 +133,34 @@ import sys
IS_PYPY = "__pypy__" in sys.builtin_module_names 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 from xdis.version_info import PYTHON_VERSION_TRIPLE
import uncompyle6.parser as python_parser
from uncompyle6.parser import get_python_parser from uncompyle6.parser import get_python_parser
from uncompyle6.parsers.treenode import SyntaxTree from uncompyle6.parsers.treenode import SyntaxTree
from spark_parser import GenericASTTraversal
from uncompyle6.scanner import Code, get_scanner 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.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_function1 import make_function1
from uncompyle6.semantics.make_function2 import make_function2 from uncompyle6.semantics.make_function2 import make_function2
from uncompyle6.semantics.make_function3 import make_function3 from uncompyle6.semantics.make_function3 import make_function3
from uncompyle6.semantics.make_function36 import make_function36 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.n_actions import NonterminalActions
from uncompyle6.semantics.transform import is_docstring, TreeTransform from uncompyle6.semantics.parser_error import ParserError
from uncompyle6.semantics.consts import ( from uncompyle6.semantics.transform import TreeTransform, is_docstring
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.show import maybe_show_tree from uncompyle6.show import maybe_show_tree
from uncompyle6.util import better_repr from uncompyle6.util import better_repr
if PYTHON_VERSION_TRIPLE < (2, 5): if PYTHON_VERSION_TRIPLE < (2, 5):
@@ -553,7 +536,7 @@ class SourceWalker(GenericASTTraversal, NonterminalActions, ComprehensionMixin):
make_function1(self, node, is_lambda, nested, code_node) make_function1(self, node, is_lambda, nested, code_node)
elif self.version <= (2, 7): elif self.version <= (2, 7):
make_function2(self, node, is_lambda, nested, code_node) 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) make_function3(self, node, is_lambda, nested, code_node)
elif self.version >= (3, 6): elif self.version >= (3, 6):
make_function36(self, node, is_lambda, nested, code_node) make_function36(self, node, is_lambda, nested, code_node)

View File

@@ -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 # 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 # 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": if sstmt[0] == "ann_assign":
sstmt[0] = ann_assign_init sstmt[0] = ann_assign_init
else: else:
sstmt[0][0] = ann_assing_init sstmt[0][0] = ann_assign_init
sstmt[0].transformed_by = "n_stmts" sstmt[0].transformed_by = "n_stmts"
pass pass
pass pass