File tree Expand file tree Collapse file tree 2 files changed +51
-1
lines changed Expand file tree Collapse file tree 2 files changed +51
-1
lines changed Original file line number Diff line number Diff line change @@ -1480,6 +1480,50 @@ def fn(t):
1480
1480
1481
1481
self ._compile_check (fn )
1482
1482
1483
+ def test_return_value_in_except_and_finally (self ):
1484
+ def whoo ():
1485
+ try :
1486
+ yield 1
1487
+ except ValueError :
1488
+ return 2 # noqa: B901
1489
+ finally :
1490
+ return 3 # noqa: B012, SIM107
1491
+
1492
+ def fn (t ):
1493
+ gen = whoo ()
1494
+ next (gen )
1495
+ try :
1496
+ gen .throw (ValueError )
1497
+ except StopIteration as e :
1498
+ assert e .args [0 ] == 3
1499
+ except Exception as e :
1500
+ raise AssertionError from e
1501
+ return t .sin ()
1502
+
1503
+ self ._compile_check (fn )
1504
+
1505
+ def test_return_None_in_except_and_finally (self ):
1506
+ def whoo ():
1507
+ try :
1508
+ yield 1
1509
+ except ValueError :
1510
+ return 2 # noqa: B901
1511
+ finally :
1512
+ return # noqa: B012, SIM107
1513
+
1514
+ def fn (t ):
1515
+ gen = whoo ()
1516
+ next (gen )
1517
+ try :
1518
+ gen .throw (ValueError )
1519
+ except StopIteration as e :
1520
+ assert len (e .args ) == 0
1521
+ except Exception as e :
1522
+ raise AssertionError from e
1523
+ return t .sin ()
1524
+
1525
+ self ._compile_check (fn )
1526
+
1483
1527
1484
1528
instantiate_parametrized_tests (GeneratorTests )
1485
1529
instantiate_parametrized_tests (TestGeneratorSend )
Original file line number Diff line number Diff line change @@ -3972,7 +3972,13 @@ def inline_call_(self):
3972
3972
):
3973
3973
assert isinstance (self , InliningGeneratorInstructionTranslator )
3974
3974
# When the generator returns None, we raise StopIteration
3975
- exc .raise_observed_exception (StopIteration , self )
3975
+ args = []
3976
+ if (
3977
+ isinstance (self .symbolic_result , ConstantVariable )
3978
+ and self .symbolic_result .value is not None
3979
+ ):
3980
+ args = [self .symbolic_result ]
3981
+ exc .raise_observed_exception (StopIteration , self , args = args )
3976
3982
else :
3977
3983
return self .symbolic_result
3978
3984
else :
You can’t perform that action at this time.
0 commit comments