summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_grammar.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/test/test_grammar.py')
-rw-r--r--Lib/test/test_grammar.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py
index 78d9459..2ed73e3 100644
--- a/Lib/test/test_grammar.py
+++ b/Lib/test/test_grammar.py
@@ -991,6 +991,60 @@ class GrammarTests(unittest.TestCase):
return 4
self.assertEqual(g3(), 4)
+ def test_break_in_finally_after_return(self):
+ # See issue #37830
+ def g1(x):
+ for count in [0, 1]:
+ count2 = 0
+ while count2 < 20:
+ count2 += 10
+ try:
+ return count + count2
+ finally:
+ if x:
+ break
+ return 'end', count, count2
+ self.assertEqual(g1(False), 10)
+ self.assertEqual(g1(True), ('end', 1, 10))
+
+ def g2(x):
+ for count in [0, 1]:
+ for count2 in [10, 20]:
+ try:
+ return count + count2
+ finally:
+ if x:
+ break
+ return 'end', count, count2
+ self.assertEqual(g2(False), 10)
+ self.assertEqual(g2(True), ('end', 1, 10))
+
+ def test_continue_in_finally_after_return(self):
+ # See issue #37830
+ def g1(x):
+ count = 0
+ while count < 100:
+ count += 1
+ try:
+ return count
+ finally:
+ if x:
+ continue
+ return 'end', count
+ self.assertEqual(g1(False), 1)
+ self.assertEqual(g1(True), ('end', 100))
+
+ def g2(x):
+ for count in [0, 1]:
+ try:
+ return count
+ finally:
+ if x:
+ continue
+ return 'end', count
+ self.assertEqual(g2(False), 0)
+ self.assertEqual(g2(True), ('end', 1))
+
def test_yield(self):
# Allowed as standalone statement
def g(): yield 1