@@ -34,28 +34,61 @@ class OutputArtifact(ArtifactVersionResponse):
3434StepRunOutputs = Union [None , OutputArtifact , Tuple [OutputArtifact , ...]]
3535
3636
37- class ArtifactFuture :
38- """Future for a step run output artifact ."""
37+ class _BaseStepRunFuture :
38+ """Base step run future ."""
3939
4040 def __init__ (
41- self , wrapped : Future [StepRunOutputs ], invocation_id : str , index : int
41+ self ,
42+ wrapped : Future [StepRunOutputs ],
43+ invocation_id : str ,
44+ ** kwargs : Any ,
4245 ) -> None :
43- """Initialize the future.
46+ """Initialize the dynamic step run future.
4447
4548 Args:
4649 wrapped: The wrapped future object.
4750 invocation_id: The invocation ID of the step run.
51+ **kwargs: Additional keyword arguments.
4852 """
4953 self ._wrapped = wrapped
5054 self ._invocation_id = invocation_id
51- self ._index = index
55+
56+ @property
57+ def invocation_id (self ) -> str :
58+ """The step run invocation ID.
59+
60+ Returns:
61+ The step run invocation ID.
62+ """
63+ return self ._invocation_id
5264
5365 def _wait (self ) -> None :
66+ """Wait for the step run future to complete."""
5467 self ._wrapped .result ()
5568
69+
70+ class ArtifactFuture (_BaseStepRunFuture ):
71+ """Future for a step run output artifact."""
72+
73+ def __init__ (
74+ self , wrapped : Future [StepRunOutputs ], invocation_id : str , index : int
75+ ) -> None :
76+ """Initialize the future.
77+
78+ Args:
79+ wrapped: The wrapped future object.
80+ invocation_id: The invocation ID of the step run.
81+ index: The index of the output artifact.
82+ """
83+ super ().__init__ (wrapped = wrapped , invocation_id = invocation_id )
84+ self ._index = index
85+
5686 def result (self ) -> OutputArtifact :
5787 """Get the step run output artifact.
5888
89+ Raises:
90+ RuntimeError: If the future returned an invalid output.
91+
5992 Returns:
6093 The step run output artifact.
6194 """
@@ -66,7 +99,8 @@ def result(self) -> OutputArtifact:
6699 return result [self ._index ]
67100 else :
68101 raise RuntimeError (
69- f"Step { self ._invocation_id } returned an invalid output: { result } "
102+ f"Step { self ._invocation_id } returned an invalid output: "
103+ f"{ result } ."
70104 )
71105
72106 def load (self ) -> Any :
@@ -78,7 +112,7 @@ def load(self) -> Any:
78112 return self .result ().load ()
79113
80114
81- class StepRunOutputsFuture :
115+ class StepRunOutputsFuture ( _BaseStepRunFuture ) :
82116 """Future for a step run output."""
83117
84118 def __init__ (
@@ -92,14 +126,11 @@ def __init__(
92126 Args:
93127 wrapped: The wrapped future object.
94128 invocation_id: The invocation ID of the step run.
129+ output_keys: The output keys of the step run.
95130 """
96- self ._wrapped = wrapped
97- self ._invocation_id = invocation_id
131+ super ().__init__ (wrapped = wrapped , invocation_id = invocation_id )
98132 self ._output_keys = output_keys
99133
100- def _wait (self ) -> None :
101- self ._wrapped .result ()
102-
103134 def artifacts (self ) -> StepRunOutputs :
104135 """Get the step run output artifacts.
105136
0 commit comments