File tree Expand file tree Collapse file tree 2 files changed +38
-0
lines changed
Expand file tree Collapse file tree 2 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -389,6 +389,24 @@ def __repr__(self):
389389 name , uuid = self .name , self .uuid
390390 return f"Job({ name = } , { uuid = } )"
391391
392+ def __getitem__ (self , key : Any ) -> OutputReference :
393+ """
394+ Get the corresponding `OutputReference` for the `Job`.
395+
396+ This is for when it is indexed like a dictionary or list.
397+
398+ Parameters
399+ ----------
400+ key
401+ The index/key.
402+
403+ Returns
404+ -------
405+ OutputReference
406+ The equivalent of `Job.output[k]`
407+ """
408+ return self .output [key ]
409+
392410 def __contains__ (self , item : Hashable ) -> bool :
393411 """
394412 Check if the job contains a reference to a given UUID.
Original file line number Diff line number Diff line change @@ -1353,3 +1353,23 @@ def test_flow_repr():
13531353 assert len (lines ) == len (flow_repr )
13541354 for expected , line in zip (lines , flow_repr ):
13551355 assert line .startswith (expected ), f"{ line = } doesn't start with { expected = } "
1356+
1357+
1358+ def test_get_item ():
1359+ from jobflow import Flow , job , run_locally
1360+
1361+ @job
1362+ def make_str (s ):
1363+ return {"hello" : s }
1364+
1365+ @job
1366+ def capitalize (s ):
1367+ return s .upper ()
1368+
1369+ job1 = make_str ("world" )
1370+ job2 = capitalize (job1 ["hello" ])
1371+
1372+ flow = Flow ([job1 , job2 ])
1373+
1374+ responses = run_locally (flow , ensure_success = True )
1375+ assert responses [job2 .uuid ][1 ].output == "WORLD"
You can’t perform that action at this time.
0 commit comments