Fix bug 3.5+ in handling nested decorators

This commit is contained in:
rocky
2019-12-21 22:51:15 -05:00
parent d50834193c
commit 8f4343ef22
7 changed files with 38 additions and 6 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -1,9 +1,34 @@
# From python 2.5 make_decorators.py
# Bug was in not recognizing @memoize which uses grammra rules
# Bug was in not recognizing @memoize which uses grammar rules
# using nonterminals mkfuncdeco and mkfuncdeco0
# This file is RUNNABLE!
def memoize(func):
pass
def test_memoize(self):
@memoize
def double(x):
return x * 2
# Seen in 3.7 test/test_c_locale_coercion.py
# Bug was handling multiple decorators in 3.5+
# simply because we didn't carry over parser rules over from
# earlier versions.
x = 1
def decorator(func):
def inc_x():
global x
x += 1
func()
return inc_x
@decorator
@decorator
def fn():
return
assert x == 1
fn()
assert x == 3

View File

@@ -4,3 +4,13 @@ from functools import total_ordering
@total_ordering
class Frame:
pass
# From 3.7 test/test_c_locale_coercion.py
# Bug is multiple decorators
@test
@unittest
class LocaleCoercionTests():
# Test implicit reconfiguration of the environment during CLI startup
pass

View File

@@ -191,7 +191,6 @@ case $PYVERSION in
[test_bdb.py]=1 #
[test_buffer.py]=1 #
[test_builtin.py]=1 #
[test_c_locale_coercion.py]=1 # Parse error
[test_cmdline.py]=1 # Interactive?
[test_codecs-3.7.py]=1
[test_collections.py]=1 # Investigate syntax error: self.assertEqual(p, Point(**))

View File

@@ -835,11 +835,8 @@ class Python3Parser(PythonParser):
dict_comp ::= LOAD_DICTCOMP LOAD_STR MAKE_FUNCTION_0 expr
GET_ITER CALL_FUNCTION_1
classdefdeco1 ::= expr classdefdeco2 CALL_FUNCTION_1
classdefdeco1 ::= expr classdefdeco1 CALL_FUNCTION_1
"""
if self.version < 3.5:
rule += """
classdefdeco1 ::= expr classdefdeco1 CALL_FUNCTION_1
"""
self.addRule(rule, nop_func)
self.custom_classfunc_rule(

View File

@@ -424,6 +424,7 @@ class Python37BaseParser(PythonParser):
dict_comp ::= LOAD_DICTCOMP LOAD_STR MAKE_FUNCTION_0 expr
GET_ITER CALL_FUNCTION_1
classdefdeco1 ::= expr classdefdeco2 CALL_FUNCTION_1
classdefdeco1 ::= expr classdefdeco1 CALL_FUNCTION_1
"""
self.addRule(rule, nop_func)