File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -198,6 +198,8 @@ def _run_task(self):
198198 self .output_ = {output_names [0 ]: output }
199199 elif isinstance (output , tuple ) and len (output_names ) == len (output ):
200200 self .output_ = dict (zip (output_names , output ))
201+ elif isinstance (output , dict ):
202+ self .output_ = {key : output .get (key , None ) for key in output_names }
201203 else :
202204 raise RuntimeError (
203205 f"expected { len (self .output_spec .fields )} elements, "
Original file line number Diff line number Diff line change @@ -114,6 +114,27 @@ def testfunc(
114114 ]
115115
116116
117+ def test_annotated_func_dictreturn (use_validator ):
118+ """Test mapping from returned dictionary to output spec."""
119+
120+ @mark .task
121+ @mark .annotate ({"return" : {"sum" : int , "mul" : int }})
122+ def testfunc (a : int , b : int ):
123+ return dict (sum = a + b , diff = a - b )
124+
125+ task = testfunc (a = 2 , b = 3 )
126+ result = task ()
127+
128+ # Part of the annotation and returned, should be exposed to output.
129+ assert result .output .sum == 5
130+
131+ # Part of the annotation but not returned, should be coalesced to None.
132+ assert result .output .mul is None
133+
134+ # Not part of the annotation, should be discarded.
135+ assert not hasattr (result .output , "diff" )
136+
137+
117138def test_annotated_func_multreturn (use_validator ):
118139 """the function has two elements in the return statement"""
119140
You can’t perform that action at this time.
0 commit comments