Skip to content

Commit 154dabf

Browse files
committed
Handle Python 3.4 MAKE_CLOSURE fns ...
Is done just like Python 3.3
1 parent 42d26cc commit 154dabf

File tree

4 files changed

+31
-9
lines changed

4 files changed

+31
-9
lines changed
1005 Bytes
Binary file not shown.
722 Bytes
Binary file not shown.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Related to #426
2+
3+
# This file is RUNNABLE!
4+
"""This program is self-checking!"""
5+
6+
a = 5
7+
class MakeClosureTest():
8+
# This function uses MAKE_CLOSURE with annotation args
9+
def __init__(self, dev: str, b: bool):
10+
super().__init__()
11+
self.dev = dev
12+
self.b = b
13+
self.a = a
14+
15+
x = MakeClosureTest("dev", True)
16+
assert x.dev == "dev"
17+
assert x.b == True
18+
assert x.a == 5

uncompyle6/parsers/parse3.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -845,18 +845,18 @@ def customize_grammar_rules(self, tokens, customize):
845845

846846
elif opname in ("BUILD_CONST_LIST", "BUILD_CONST_DICT", "BUILD_CONST_SET"):
847847
if opname == "BUILD_CONST_DICT":
848-
rule = f"""
848+
rule = """
849849
add_consts ::= ADD_VALUE*
850-
const_list ::= COLLECTION_START add_consts {opname}
850+
const_list ::= COLLECTION_START add_consts %s
851851
dict ::= const_list
852852
expr ::= dict
853-
"""
853+
""" % opname
854854
else:
855-
rule = f"""
855+
rule = """
856856
add_consts ::= ADD_VALUE*
857-
const_list ::= COLLECTION_START add_consts {opname}
857+
const_list ::= COLLECTION_START add_consts %s
858858
expr ::= const_list
859-
"""
859+
""" % opname
860860
self.addRule(rule, nop_func)
861861

862862
elif opname_base in (
@@ -1178,7 +1178,9 @@ def customize_grammar_rules(self, tokens, customize):
11781178
"pos_arg " * args_pos,
11791179
opname,
11801180
)
1181-
elif self.version == (3, 3):
1181+
self.add_unique_rule(rule, opname, token.attr, customize)
1182+
1183+
elif (3, 3) <= self.version < (3, 5):
11821184
if annotate_args > 0:
11831185
rule = (
11841186
"mkfunc_annotate ::= %s%s%sannotate_tuple load_closure LOAD_CODE LOAD_STR %s"
@@ -1195,8 +1197,10 @@ def customize_grammar_rules(self, tokens, customize):
11951197
"pos_arg " * args_pos,
11961198
opname,
11971199
)
1200+
self.add_unique_rule(rule, opname, token.attr, customize)
11981201

1199-
elif self.version >= (3, 4):
1202+
1203+
if self.version >= (3, 4):
12001204
if not self.is_pypy:
12011205
load_op = "LOAD_STR"
12021206
else:
@@ -1221,7 +1225,7 @@ def customize_grammar_rules(self, tokens, customize):
12211225
opname,
12221226
)
12231227

1224-
self.add_unique_rule(rule, opname, token.attr, customize)
1228+
self.add_unique_rule(rule, opname, token.attr, customize)
12251229

12261230
if args_kw == 0:
12271231
rule = "mkfunc ::= %sload_closure load_genexpr %s" % (

0 commit comments

Comments
 (0)