X Tutup
Skip to content

Commit e63bcd5

Browse files
committed
Another Python 3 closure grammar bug
1 parent 73461d3 commit e63bcd5

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed
596 Bytes
Binary file not shown.
469 Bytes
Binary file not shown.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Tests bug in Python 3
2+
3+
# load_closure ::= LOAD_CLOSURE BUILD_TUPLE_1
4+
5+
# Python 3.5
6+
# mkfunc ::= load_closure LOAD_CONST LOAD_CONST MAKE_CLOSURE_0
7+
8+
# Python 3.2
9+
# mkfunc ::= load_closure LOAD_CONST MAKE_CLOSURE_0
10+
11+
# mkfuncdeco0 ::= mkfunc
12+
# mkfuncdeco ::= expr mkfuncdeco0 CALL_FUNCTION_1
13+
# designator ::= STORE_FAST
14+
# funcdefdeco ::= mkfuncdeco designator
15+
# stmt ::= funcdefdeco
16+
17+
18+
19+
from functools import wraps
20+
21+
def contextmanager(func):
22+
@wraps(func)
23+
def helper(*args, **kwds):
24+
return _GeneratorContextManager(func, *args, **kwds)
25+
return helper

uncompyle6/parsers/parse3.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,10 +528,19 @@ def add_custom_rules(self, tokens, customize):
528528
'expr GET_ITER CALL_FUNCTION_1' %
529529
('expr '* token.attr, opname),
530530
opname, token.attr, customize)
531-
rule = ('mkfunc ::= %s load_closure BUILD_TUPLE_1 LOAD_CONST LOAD_CONST %s'
531+
532+
rule = ('mkfunc ::= %s load_closure LOAD_CONST %s'
533+
% ('expr ' * token.attr, opname))
534+
535+
# Python 3.5+ instead of above?
536+
rule = ('mkfunc ::= %s load_closure LOAD_CONST LOAD_CONST %s'
537+
% ('expr ' * token.attr, opname))
538+
539+
self.add_unique_rule(rule, opname, token.attr, customize)
540+
rule = ('mkfunc ::= %s load_closure load_genexpr %s'
532541
% ('expr ' * token.attr, opname))
533542
self.add_unique_rule(rule, opname, token.attr, customize)
534-
rule = ('mkfunc ::= %s load_closure BUILD_TUPLE_1 LOAD_GENXPR LOAD_CONST %s'
543+
rule = ('mkfunc ::= %s load_closure LOAD_CONST %s'
535544
% ('expr ' * token.attr, opname))
536545
self.add_unique_rule(rule, opname, token.attr, customize)
537546
return

0 commit comments

Comments
 (0)
X Tutup