Skip to content

Comments

fix: widen type annotations for compound/parallel state transitions#580

Merged
fgmacedo merged 4 commits intodevelopfrom
fix/compound-state-type-annotations
Feb 22, 2026
Merged

fix: widen type annotations for compound/parallel state transitions#580
fgmacedo merged 4 commits intodevelopfrom
fix/compound-state-type-annotations

Conversation

@fgmacedo
Copy link
Owner

Summary

  • Type annotations: NestedStateFactory.__new__ returns a State instance at runtime, but mypy sees class Foo(State.Compound) as type[Foo]. Widened _ToState.__call__, _FromState.__call__, and the metaclass stubs to accept NestedStateFactory in the union, removing the need for # type: ignore[arg-type] in example files.
  • AI Shell example: added tests/examples/ai_shell.py — a feature-rich coding assistant demonstrating parallel states, compound states, HistoryState, eventless transitions, In() guards, done.state, error.execution, and raise_().
  • Engine support: invoke/error.execution infrastructure, event id helpers, and related test coverage for compound and parallel statecharts.

NestedStateFactory.__new__ returns a State instance at runtime, but mypy
sees class Foo(State.Compound) as type[Foo]. Accept NestedStateFactory in
the union type of _ToState, _FromState, and the metaclass stubs so that
compound/parallel states work as transition targets without type: ignore.

Also includes: ai_shell example, invoke/error.execution engine support,
event id helpers, and related test coverage.
Move PEP 723 script metadata after the module docstring and add RST
title with underline so sphinx-gallery recognizes the example correctly.
@codecov
Copy link

codecov bot commented Feb 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (f60429d) to head (e4a11b5).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files
@@            Coverage Diff            @@
##           develop      #580   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           33        33           
  Lines         4134      4145   +11     
  Branches       662       662           
=========================================
+ Hits          4134      4145   +11     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

- Rename to ai_shell_machine.py to match gallery filename_pattern
- Move PEP 723 metadata after docstring so gallery finds the RST title
- Lazy-import openai so the class definition works without the package
  (allows diagram generation during docs build)
- Skip sphinx-gallery execution via sys.modules guard
- Graceful degradation: main() prints a message if openai is missing
…mple

Replace manual `raise_()` routing with `invoke` handlers in the
`thinking` and `using_tool` states. The invoke feature runs I/O work in
background threads with automatic `done.invoke` event routing, which is
a better fit for these states and showcases the feature in a practical
example.

Also add a warning/disclaimer about LLM shell access risks, and sync
the main loop with a threading.Event to wait for invoke completion
before re-prompting.
@sonarqubecloud
Copy link

@fgmacedo fgmacedo merged commit 300cb34 into develop Feb 22, 2026
14 checks passed
@fgmacedo fgmacedo deleted the fix/compound-state-type-annotations branch February 22, 2026 00:13
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