Port over some recent decompyle3 3.8 fixes

This commit is contained in:
rocky
2022-06-26 04:26:15 -04:00
parent 7f798541f0
commit 85ba8352ba
7 changed files with 219 additions and 5 deletions

View File

@@ -50,14 +50,15 @@ NO_PARENTHESIS_EVER = 100
# fmt: off
PRECEDENCE = {
"named_expr": 40, # :=
"yield": 38, # Needs to be below named_expr
"yield_from": 38,
"tuple_list_starred": 38, # *x, *y, *z - about at the level of yield?
"dict_unpack": 38, # **kwargs
"list_unpack": 38, # *args
"yield_from": 38,
"tuple_list_starred": 38, # *x, *y, *z - about at the level of yield?
"_lambda_body": 30,
"lambda_body": 30, # lambda ... : lambda_body
"lambda_body": 32, # lambda ... : lambda_body
"yield": 30, # Needs to be below named_expr and lambda_body
"if_exp": 28, # IfExp ( a if x else b)
"if_exp_lambda": 28, # IfExp involving a lambda expression

View File

@@ -66,6 +66,9 @@ def customize_for_version38(self, version):
(1, "c_suite_stmts_opt"),
(-2, "c_suite_stmts_opt"),
),
# Python 3.8 reverses the order of keys and items
# from all prior versions of Python.
"dict_comp_body": ("%c: %c", (0, "expr"), (1, "expr"),),
"except_cond1a": ("%|except %c:\n", (1, "expr"),),
"except_cond_as": (
"%|except %c as %c:\n",

View File

@@ -302,6 +302,9 @@ class ComprehensionMixin:
store = set_iter_async[1]
assert store == "store"
n = set_iter_async[2]
elif node == "list_comp" and tree[0] == "expr":
tree = tree[0][0]
n = tree[iter_index]
else:
n = tree[iter_index]