fix lint: combine with statements

This commit is contained in:
2026-03-19 22:36:35 -07:00
parent ff08b1d6f5
commit 4f2cf49a80
3 changed files with 136 additions and 9 deletions

View File

@@ -185,8 +185,6 @@ class Pipeline:
return True
return True
def replace_stage(
self, name: str, new_stage: Stage, preserve_state: bool = True
) -> Stage | None:
@@ -304,11 +302,16 @@ class Pipeline:
self._capability_map = self._build_capability_map()
self._execution_order = self._resolve_dependencies()
try:
self._validate_dependencies()
self._validate_types()
except StageError:
pass
# Note: We intentionally DO NOT validate dependencies here.
# Mutation operations (remove/swap/move) might leave the pipeline
# temporarily invalid (e.g., removing a stage that others depend on).
# Validation is performed explicitly in build() or can be checked
# manually via validate_minimum_capabilities().
# try:
# self._validate_dependencies()
# self._validate_types()
# except StageError:
# pass
# Restore initialized state
self._initialized = was_initialized
@@ -504,6 +507,16 @@ class Pipeline:
self._capability_map = self._build_capability_map()
self._execution_order = self._resolve_dependencies()
# Re-validate after injection attempt (whether anything was injected or not)
# If injection didn't run (injected empty), we still need to check if we're valid
# If injection ran but failed to fix (injected empty), we need to check
is_valid, missing = self.validate_minimum_capabilities()
if not is_valid:
raise StageError(
"build",
f"Auto-injection failed to provide minimum capabilities: {missing}",
)
self._validate_dependencies()
self._validate_types()
self._initialized = True
@@ -712,8 +725,9 @@ class Pipeline:
frame_start = time.perf_counter() if self._metrics_enabled else 0
stage_timings: list[StageMetrics] = []
# Separate overlay stages from regular stages
# Separate overlay stages and display stage from regular stages
overlay_stages: list[tuple[int, Stage]] = []
display_stage: Stage | None = None
regular_stages: list[str] = []
for name in self._execution_order:
@@ -721,6 +735,11 @@ class Pipeline:
if not stage or not stage.is_enabled():
continue
# Check if this is the display stage - execute last
if stage.category == "display":
display_stage = stage
continue
# Safely check is_overlay - handle MagicMock and other non-bool returns
try:
is_overlay = bool(getattr(stage, "is_overlay", False))
@@ -737,7 +756,7 @@ class Pipeline:
else:
regular_stages.append(name)
# Execute regular stages in dependency order
# Execute regular stages in dependency order (excluding display)
for name in regular_stages:
stage = self._stages.get(name)
if not stage or not stage.is_enabled():
@@ -828,6 +847,35 @@ class Pipeline:
)
)
# Execute display stage LAST (after overlay stages)
# This ensures overlay effects like HUD are visible in the final output
if display_stage:
stage_start = time.perf_counter() if self._metrics_enabled else 0
try:
current_data = display_stage.process(current_data, self.context)
except Exception as e:
if not display_stage.optional:
return StageResult(
success=False,
data=current_data,
error=str(e),
stage_name=display_stage.name,
)
if self._metrics_enabled:
stage_duration = (time.perf_counter() - stage_start) * 1000
chars_in = len(str(data)) if data else 0
chars_out = len(str(current_data)) if current_data else 0
stage_timings.append(
StageMetrics(
name=display_stage.name,
duration_ms=stage_duration,
chars_in=chars_in,
chars_out=chars_out,
)
)
if self._metrics_enabled:
total_duration = (time.perf_counter() - frame_start) * 1000
self._frame_metrics.append(