Skip to content

Commit 1ef433f

Browse files
committed
[GR-23231] Fix nested yields with send.
PullRequest: graalpython/1180
2 parents 4c7453f + 4606aa7 commit 1ef433f

File tree

3 files changed

+37
-28
lines changed

3 files changed

+37
-28
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_generators.py

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -235,26 +235,33 @@ def f():
235235
next(g)
236236

237237

238-
# def test_return_tuple(self):
239-
# def g():
240-
# return (yield 1)
241-
242-
# gen = g()
243-
# self.assertEqual(next(gen), 1)
244-
# with self.assertRaises(StopIteration) as cm:
245-
# gen.send((2,))
246-
# self.assertEqual(cm.exception.value, (2,))
247-
248-
# def test_return_stopiteration(self):
249-
# def g():
250-
# return (yield 1)
251-
252-
# gen = g()
253-
# self.assertEqual(next(gen), 1)
254-
# with self.assertRaises(StopIteration) as cm:
255-
# gen.send(StopIteration(2))
256-
# self.assertTrue(isinstance(cm.exception.value, StopIteration))
257-
# self.assertEqual(cm.exception.value.value, 2)
238+
def test_return_tuple(self):
239+
def g():
240+
return (yield 1)
241+
242+
gen = g()
243+
self.assertEqual(next(gen), 1)
244+
with self.assertRaises(StopIteration) as cm:
245+
gen.send((2,))
246+
self.assertEqual(cm.exception.value, (2,))
247+
248+
def test_return_stopiteration(self):
249+
def g():
250+
return (yield 1)
251+
252+
gen = g()
253+
self.assertEqual(next(gen), 1)
254+
with self.assertRaises(StopIteration) as cm:
255+
gen.send(StopIteration(2))
256+
self.assertTrue(isinstance(cm.exception.value, StopIteration))
257+
self.assertEqual(cm.exception.value.value, 2)
258+
259+
def test_yield_expr_value_without_send(self):
260+
def fn():
261+
yield (1,(yield 42))
262+
g = fn()
263+
self.assertEqual(next(g), 42)
264+
self.assertEqual(next(g), (1,None))
258265

259266
def test_generator_caller_frame(self):
260267
def gen():

graalpython/com.oracle.graal.python.test/src/tests/unittest_tags/test_fstring.txt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,35 +9,34 @@
99
*graalpython.lib-python.3.test.test_fstring.TestCase.test_ast_line_numbers_multiple_formattedvalues
1010
*graalpython.lib-python.3.test.test_fstring.TestCase.test_ast_line_numbers_nested
1111
*graalpython.lib-python.3.test.test_fstring.TestCase.test_backslash_char
12+
*graalpython.lib-python.3.test.test_fstring.TestCase.test_backslashes_in_string_part
1213
*graalpython.lib-python.3.test.test_fstring.TestCase.test_call
1314
*graalpython.lib-python.3.test.test_fstring.TestCase.test_closure
1415
*graalpython.lib-python.3.test.test_fstring.TestCase.test_comments
1516
*graalpython.lib-python.3.test.test_fstring.TestCase.test_compile_time_concat
1617
*graalpython.lib-python.3.test.test_fstring.TestCase.test_compile_time_concat_errors
1718
*graalpython.lib-python.3.test.test_fstring.TestCase.test_conversions
18-
*graalpython.lib-python.3.test.test_fstring.TestCase.test_backslashes_in_string_part
1919
*graalpython.lib-python.3.test.test_fstring.TestCase.test_debug_conversion
20-
*graalpython.lib-python.3.test.test_fstring.TestCase.test_format_specifier_expressions
21-
*graalpython.lib-python.3.test.test_fstring.TestCase.test_errors
22-
*graalpython.lib-python.3.test.test_fstring.TestCase.test_global
23-
*graalpython.lib-python.3.test.test_fstring.TestCase.test_lambda
24-
*graalpython.lib-python.3.test.test_fstring.TestCase.test_misformed_unicode_character_name
25-
*graalpython.lib-python.3.test.test_fstring.TestCase.test_no_backslashes_in_expression_part
2620
*graalpython.lib-python.3.test.test_fstring.TestCase.test_del
2721
*graalpython.lib-python.3.test.test_fstring.TestCase.test_dict
2822
*graalpython.lib-python.3.test.test_fstring.TestCase.test_docstring
2923
*graalpython.lib-python.3.test.test_fstring.TestCase.test_double_braces
3024
*graalpython.lib-python.3.test.test_fstring.TestCase.test_empty_format_specifier
3125
*graalpython.lib-python.3.test.test_fstring.TestCase.test_equal_equal
26+
*graalpython.lib-python.3.test.test_fstring.TestCase.test_errors
3227
*graalpython.lib-python.3.test.test_fstring.TestCase.test_expressions_with_triple_quoted_strings
28+
*graalpython.lib-python.3.test.test_fstring.TestCase.test_format_specifier_expressions
29+
*graalpython.lib-python.3.test.test_fstring.TestCase.test_global
3330
*graalpython.lib-python.3.test.test_fstring.TestCase.test_if_conditional
3431
*graalpython.lib-python.3.test.test_fstring.TestCase.test_invalid_string_prefixes
32+
*graalpython.lib-python.3.test.test_fstring.TestCase.test_lambda
3533
*graalpython.lib-python.3.test.test_fstring.TestCase.test_leading_trailing_spaces
3634
*graalpython.lib-python.3.test.test_fstring.TestCase.test_literal
3735
*graalpython.lib-python.3.test.test_fstring.TestCase.test_literal_eval
3836
*graalpython.lib-python.3.test.test_fstring.TestCase.test_locals
3937
*graalpython.lib-python.3.test.test_fstring.TestCase.test_loop
4038
*graalpython.lib-python.3.test.test_fstring.TestCase.test_many_expressions
39+
*graalpython.lib-python.3.test.test_fstring.TestCase.test_misformed_unicode_character_name
4140
*graalpython.lib-python.3.test.test_fstring.TestCase.test_mismatched_braces
4241
*graalpython.lib-python.3.test.test_fstring.TestCase.test_mismatched_parens
4342
*graalpython.lib-python.3.test.test_fstring.TestCase.test_missing_expression
@@ -46,6 +45,7 @@
4645
*graalpython.lib-python.3.test.test_fstring.TestCase.test_multiple_vars
4746
*graalpython.lib-python.3.test.test_fstring.TestCase.test_nested_fstrings
4847
*graalpython.lib-python.3.test.test_fstring.TestCase.test_newlines_in_expressions
48+
*graalpython.lib-python.3.test.test_fstring.TestCase.test_no_backslashes_in_expression_part
4949
*graalpython.lib-python.3.test.test_fstring.TestCase.test_no_escapes_for_braces
5050
*graalpython.lib-python.3.test.test_fstring.TestCase.test_not_equal
5151
*graalpython.lib-python.3.test.test_fstring.TestCase.test_parens_in_expressions
@@ -54,3 +54,4 @@
5454
*graalpython.lib-python.3.test.test_fstring.TestCase.test_str_format_differences
5555
*graalpython.lib-python.3.test.test_fstring.TestCase.test_unterminated_string
5656
*graalpython.lib-python.3.test.test_fstring.TestCase.test_yield
57+
*graalpython.lib-python.3.test.test_fstring.TestCase.test_yield_send

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/generator/YieldNode.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,10 @@ public Object execute(VirtualFrame frame) {
6868
return specialArgument;
6969
}
7070
} else {
71+
Object result = right.execute(frame);
7172
access.setActive(frame, flagSlot, true);
7273
access.setLastYieldIndex(frame, yieldIndex);
73-
throw new YieldException(right.execute(frame));
74+
throw new YieldException(result);
7475
}
7576
}
7677
}

0 commit comments

Comments
 (0)