File tree Expand file tree Collapse file tree 3 files changed +110
-81
lines changed Expand file tree Collapse file tree 3 files changed +110
-81
lines changed Original file line number Diff line number Diff line change @@ -625,6 +625,7 @@ def generator_wrapper(
625
625
inspect .signature (func ).parameters .get ("run_tree" , None ) is not None
626
626
)
627
627
results : List [Any ] = []
628
+ function_return : Any = None
628
629
try :
629
630
if func_accepts_parent_run :
630
631
kwargs ["run_tree" ] = run_container ["new_run" ]
@@ -653,8 +654,13 @@ def generator_wrapper(
653
654
yield item
654
655
except GeneratorExit :
655
656
break
656
- except StopIteration :
657
- pass
657
+ except StopIteration as e :
658
+ function_return = e .value
659
+ if function_return is not None :
660
+ # In 99% of cases, people yield OR return; to keep
661
+ # backwards compatibility, we'll only return if there's
662
+ # return value is non-null.
663
+ results .append (function_return )
658
664
659
665
except BaseException as e :
660
666
_on_run_end (run_container , error = e )
@@ -671,6 +677,7 @@ def generator_wrapper(
671
677
else :
672
678
function_result = None
673
679
_on_run_end (run_container , outputs = function_result )
680
+ return function_return
674
681
675
682
if inspect .isasyncgenfunction (func ):
676
683
selected_wrapper : Callable = async_generator_wrapper
You can’t perform that action at this time.
0 commit comments