Skip to content

Commit e12d840

Browse files
committed
2.x tolerance
1 parent 83f3424 commit e12d840

File tree

4 files changed

+35
-28
lines changed

4 files changed

+35
-28
lines changed

uncompyle6/parsers/reducecheck/whilestmt.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2020 Rocky Bernstein
1+
# Copyright (c) 2020, 2024 Rocky Bernstein
22
# This program is free software: you can redistribute it and/or modify
33
# it under the terms of the GNU General Public License as published by
44
# the Free Software Foundation, either version 3 of the License, or
@@ -13,9 +13,7 @@
1313
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1414

1515

16-
def whilestmt(
17-
self, lhs: str, n: int, rule, tree, tokens: list, first: int, last: int
18-
) -> bool:
16+
def whilestmt(self, lhs, n, rule, tree, tokens, first, last):
1917
# When we are missing a COME_FROM_LOOP, the
2018
# "while" statement is nested inside an if/else
2119
# so after the POP_BLOCK we have a JUMP_FORWARD which forms the "else" portion of the "if"

uncompyle6/parsers/reducecheck/whilestmt38.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2022 Rocky Bernstein
1+
# Copyright (c) 2022, 2024 Rocky Bernstein
22
# This program is free software: you can redistribute it and/or modify
33
# it under the terms of the GNU General Public License as published by
44
# the Free Software Foundation, either version 3 of the License, or
@@ -13,9 +13,7 @@
1313
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1414

1515

16-
def whilestmt38_check(
17-
self, lhs: str, n: int, rule, ast, tokens: list, first: int, last: int
18-
) -> bool:
16+
def whilestmt38_check(self, lhs, n, rule, ast, tokens, first, last):
1917
# When we are missing a COME_FROM_LOOP, the
2018
# "while" statement is nested inside an if/else
2119
# so after the POP_BLOCK we have a JUMP_FORWARD which forms the "else" portion of the "if"

uncompyle6/scanners/scanner30.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
# Copyright (c) 2016-2017, 2020-2022 by Rocky Bernstein
1+
# Copyright (c) 2016-2017, 2020-2022, 2024 by Rocky Bernstein
22
"""
33
Python 3.0 bytecode scanner/deparser
44
55
This sets up opcodes Python's 3.0 and calls a generalized
66
scanner routine for Python 3.
77
"""
88

9-
from __future__ import print_function
10-
119
import xdis
1210
from xdis import instruction_size
1311

uncompyle6/semantics/gencomp-for-3.0.py

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2022-2023 by Rocky Bernstein
1+
# Copyright (c) 2022-2024 by Rocky Bernstein
22
#
33
# This program is free software: you can redistribute it and/or modify
44
# it under the terms of the GNU General Public License as published by
@@ -46,7 +46,10 @@ def closure_walk(self, node, collection_index):
4646
p = self.prec
4747
self.prec = PRECEDENCE["lambda_body"] - 1
4848

49-
code_index = 0 if node[0] == "load_genexpr" else 1
49+
if node[0] == "load_genexpr":
50+
code_index = 0
51+
else:
52+
code_index = 1
5053
tree = self.get_comprehension_function(node, code_index=code_index)
5154

5255
# Remove single reductions as in ("stmts", "sstmt"):
@@ -56,7 +59,10 @@ def closure_walk(self, node, collection_index):
5659
store = tree[3]
5760
collection = node[collection_index]
5861

59-
iter_index = 3 if tree == "genexpr_func_async" else 4
62+
if tree == "genexpr_func_async":
63+
iter_index = 3
64+
else:
65+
iter_index = 4
6066
n = tree[iter_index]
6167
list_if = None
6268
assert n == "comp_iter"
@@ -98,13 +104,8 @@ def closure_walk(self, node, collection_index):
98104
self.preorder(list_if)
99105
self.prec = p
100106

101-
def comprehension_walk(
102-
self,
103-
node,
104-
iter_index: Optional[int],
105-
code_index: int = -5,
106-
):
107-
p: int = self.prec
107+
def comprehension_walk(self, node, iter_index, code_index = -5):
108+
p = self.prec
108109
self.prec = PRECEDENCE["lambda_body"] - 1
109110

110111
# FIXME: clean this up
@@ -225,8 +226,8 @@ def comprehension_walk(
225226
def comprehension_walk_newer(
226227
self,
227228
node,
228-
iter_index: Optional[int],
229-
code_index: int = -5,
229+
iter_index,
230+
code_index = -5,
230231
collection_node=None,
231232
):
232233
"""Non-closure-based comprehensions the way they are done in Python3
@@ -295,7 +296,10 @@ def comprehension_walk_newer(
295296
assert list_afor2 == "list_afor2"
296297
store = list_afor2[1]
297298
assert store == "store"
298-
n = list_afor2[3] if list_afor2[3] == "list_iter" else list_afor2[2]
299+
if list_afor2[3] == "list_iter":
300+
n = list_afor2[3]
301+
else:
302+
n = list_afor2[2]
299303
else:
300304
# ???
301305
pass
@@ -538,7 +542,7 @@ def comprehension_walk_newer(
538542
pass
539543
self.prec = p
540544

541-
def get_comprehension_function(self, node, code_index: int):
545+
def get_comprehension_function(self, node, code_index):
542546
"""
543547
Build the body of a comprehension function and then
544548
find the comprehension node buried in the tree which may
@@ -583,7 +587,10 @@ def get_comprehension_function(self, node, code_index: int):
583587

584588
while len(tree) == 1 or (tree in ("stmt", "sstmt", "return", "return_expr")):
585589
self.prec = 100
586-
tree = tree[1] if tree[0] in ("dom_start", "dom_start_opt") else tree[0]
590+
if tree[0] in ("dom_start", "dom_start_opt"):
591+
tree = tree[1]
592+
else:
593+
tree = tree[0]
587594
return tree
588595

589596
def listcomp_closure3(self, node):
@@ -688,7 +695,10 @@ def listcomp_closure3(self, node):
688695
if self.version[:2] == (3, 0) and n[2] == "list_iter":
689696
n = n[2]
690697
else:
691-
n = n[-2] if n[-1] == "come_from_opt" else n[-1]
698+
if n[-1] == "come_from_opt":
699+
n = n[-2]
700+
else:
701+
n = n[-1]
692702
pass
693703
elif n == "list_if37":
694704
list_ifs.append(n)
@@ -698,7 +708,10 @@ def listcomp_closure3(self, node):
698708
collections.append(n[0][0])
699709
n = n[1]
700710
stores.append(n[1][0])
701-
n = n[2] if n[2].kind == "list_iter" else n[3]
711+
if n[2].kind == "list_iter":
712+
n = n[2]
713+
else:
714+
n = n[3]
702715
pass
703716

704717
assert n == "lc_body", tree

0 commit comments

Comments
 (0)