fix: widen type annotations for compound/parallel state transitions#580
Merged
fix: widen type annotations for compound/parallel state transitions#580
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- 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.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
NestedStateFactory.__new__returns aStateinstance at runtime, but mypy seesclass Foo(State.Compound)astype[Foo]. Widened_ToState.__call__,_FromState.__call__, and the metaclass stubs to acceptNestedStateFactoryin the union, removing the need for# type: ignore[arg-type]in example files.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_().