3131import vgi .function
3232import vgi .ipc_utils
3333import vgi .log
34+ from vgi .output_complete import OutputComplete
3435
3536__all__ = [
3637 "TableCardinality" ,
@@ -133,47 +134,6 @@ class Output:
133134OutputGenerator = Generator [vgi .log .Message | Output , None , None ]
134135
135136
136- @dataclass (frozen = True , slots = True )
137- class _OutputComplete :
138- """Internal: Output with guaranteed non-None batch.
139-
140- Used by the framework to normalize generator yields. When the user yields
141- None, Output with None batch, or Message, this class ensures we always
142- have a valid RecordBatch for the protocol.
143-
144- Attributes:
145- batch: Always a valid RecordBatch (never None).
146- log_message: Present when user yielded Message directly.
147-
148- """
149-
150- batch : pa .RecordBatch
151- log_message : vgi .log .Message | None = None
152-
153- @classmethod
154- def from_process_result (
155- cls ,
156- source : vgi .log .Message | Output ,
157- empty_batch : pa .RecordBatch ,
158- ) -> "_OutputComplete" :
159- """Create from user's yield value.
160-
161- Args:
162- source: What the user yielded (Output or Message).
163- empty_batch: Empty batch to substitute when needed.
164-
165- Returns:
166- Normalized output with guaranteed non-None batch.
167-
168- """
169- if isinstance (source , vgi .log .Message ):
170- return cls (batch = empty_batch , log_message = source )
171- # source is Output
172- return cls (
173- batch = source .batch if source .batch is not None else empty_batch ,
174- )
175-
176-
177137@dataclass (frozen = True , slots = True )
178138class ProtocolOutput :
179139 """Output yielded by the generator after each send().
@@ -210,7 +170,7 @@ def metadata(
210170 )
211171
212172 @classmethod
213- def from_process_result (cls , process_result : "_OutputComplete " ) -> "ProtocolOutput" :
173+ def from_process_result (cls , process_result : "OutputComplete " ) -> "ProtocolOutput" :
214174 """Create a ProtocolOutput from an Output and status.
215175
216176 Args:
@@ -384,7 +344,7 @@ def process(self) -> OutputGenerator:
384344 """
385345
386346 @final
387- def _process_and_validate (self , generator : OutputGenerator ) -> _OutputComplete :
347+ def _process_and_validate (self , generator : OutputGenerator ) -> OutputComplete :
388348 """Process a batch and validate the output schema.
389349
390350 Converts the result of the generator to OutputComplete, and
@@ -400,7 +360,7 @@ def _process_and_validate(self, generator: OutputGenerator) -> _OutputComplete:
400360 SchemaValidationError: If output batch schema doesn't match.
401361
402362 """
403- result : _OutputComplete = _OutputComplete .from_process_result (
363+ result : OutputComplete = OutputComplete .from_process_result (
404364 generator .send (None ),
405365 self .empty_output_batch ,
406366 )
@@ -411,7 +371,7 @@ def _process_and_validate(self, generator: OutputGenerator) -> _OutputComplete:
411371 def _process_with_exception_handling (
412372 self ,
413373 generator : OutputGenerator ,
414- ) -> _OutputComplete :
374+ ) -> OutputComplete :
415375 """Process a batch with exception handling.
416376
417377 Wraps _process_and_validate to catch exceptions and convert them
@@ -425,13 +385,13 @@ def _process_with_exception_handling(
425385 except StopIteration :
426386 raise
427387 except Exception as e :
428- return _OutputComplete (
388+ return OutputComplete (
429389 batch = self .empty_output_batch ,
430390 log_message = vgi .log .Message .from_exception (e ),
431391 )
432392
433393 @final
434- def _should_terminate (self , result : _OutputComplete ) -> bool :
394+ def _should_terminate (self , result : OutputComplete ) -> bool :
435395 """Check if processing should terminate due to an exception."""
436396 return (
437397 result .log_message is not None
0 commit comments