Skip to content

fix(pipeline): assert result narrowed in invoke return path#243

Merged
miguelgfierro merged 1 commit into
issue-147-pipeline-evolutionfrom
fix/pyright-result-narrowing
May 28, 2026
Merged

fix(pipeline): assert result narrowed in invoke return path#243
miguelgfierro merged 1 commit into
issue-147-pipeline-evolutionfrom
fix/pyright-result-narrowing

Conversation

@miguelgfierro
Copy link
Copy Markdown
Contributor

Fixes the Type Check job failure on #232.

Pyright reported:

state_pipeline.py:652:16 - error: Type "StatePipelineResult | None" is not assignable to return type "StatePipelineResult"

The single-return-path refactor in #240 declared result: StatePipelineResult | None = None and assigned it inside the try block. Pyright cannot narrow it through a try/finally boundary (a finally can theoretically reassign), so at the return result statement it still sees None as a possibility.

Add assert result is not None before the return — same runtime guarantee (the try block always sets result either via a break or via the post-loop if result is None: fallback), and pyright now sees the non-None invariant.

Verification

  • pyright fireflyframework_agentic/pipeline/state_pipeline.py → 0 errors.
  • pytest tests/unit/pipeline/ → 142 passed.

After the try/finally introduced in #240, pyright could not narrow
result: StatePipelineResult | None to StatePipelineResult at the return
statement (a finally block can reassign, so the narrowing must be local).

Add an explicit assert before return — same runtime guarantee, makes the
non-None invariant visible to pyright.
@miguelgfierro miguelgfierro merged commit e7c342f into issue-147-pipeline-evolution May 28, 2026
@miguelgfierro miguelgfierro deleted the fix/pyright-result-narrowing branch May 28, 2026 09:26
ancongui pushed a commit that referenced this pull request May 31, 2026
…owing

fix(pipeline): assert result narrowed in invoke return path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant