File tree 2 files changed +23
-0
lines changed
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):
198
198
self .output_ = {output_names [0 ]: output }
199
199
elif isinstance (output , tuple ) and len (output_names ) == len (output ):
200
200
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 }
201
203
else :
202
204
raise RuntimeError (
203
205
f"expected { len (self .output_spec .fields )} elements, "
Original file line number Diff line number Diff line change @@ -114,6 +114,27 @@ def testfunc(
114
114
]
115
115
116
116
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
+
117
138
def test_annotated_func_multreturn (use_validator ):
118
139
"""the function has two elements in the return statement"""
119
140
You can’t perform that action at this time.
0 commit comments