harbor run -t openthoughts/tasktrove-exp-flat25-stackoverflow-v2-5k-stackoverflow-0509harbor download openthoughts/tasktrove-exp-flat25-stackoverflow-v2-5k-stackoverflow-0509Title: Implement base class PipelineStage for pipeline stages with nuanced exception handling (Python 3)
Body: I'm building a small pipeline framework used by Azure IoT device code. I need to implement a lightweight base class that all concrete pipeline stages will derive from. The tests exercise very specific exception-handling semantics, so the base class must encode those rules.
What to implement
Acceptance criteria
Notes for implementer
starter skeleton (proposed)
# azure/iot/device/common/pipeline/pipeline_stages_base.py
class PipelineStage:
def __init__(self):
self.previous = None # can be set to another stage to simulate a chain
def _run_op(self, op):
raise NotImplementedError
def run_op(self, op):
try:
self._run_op(op)
except BaseException:
# For BaseException (like KeyboardInterrupt), always re-raise
raise
except Exception as exc:
# Normal exception
if not getattr(op, 'completed', False):
op.completed = True
op.error = exc
else:
# If already completed, propagate
raise
def _handle_pipeline_event(self, event):
raise NotImplementedError
def handle_pipeline_event(self, event):
try:
self._handle_pipeline_event(event)
except BaseException:
# Propagate BaseException regardless of previous state
raise
except Exception as exc:
if self.previous is not None:
# report once, swallow
self.report_background_exception(exc)
else:
# swallow when there is no previous stage
pass
def report_background_exception(self, exc):
# Default no-op (tests can mock this)
pass
Question Would you implement this base class as described to satisfy the tests? If you have a polished patch or a complete implementation that passes the described test expectations, please share. Any tips for ensuring compatibility with existing test patches (e.g., tests that mock _run_op / _handle_pipeline_event) would be greatly appreciated.