Repository navigation
fix: honor Event(internal=True) when the event is triggered #663
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -146,7 +146,9 @@ def __get__(self, instance, owner): | |
| """ | ||
| if instance is None: | ||
| return self | ||
| return BoundEvent(id=self.id, name=self.name, delay=self.delay, _sm=instance) | ||
| return BoundEvent( | ||
| id=self.id, name=self.name, delay=self.delay, internal=self.internal, _sm=instance | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (blocking): Carrying |
||
| ) | ||
|
|
||
| def put(self, *args, send_id: "str | None" = None, **kwargs): | ||
| # The `__call__` is declared here to help IDEs knowing that an `Event` | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -483,6 +483,7 @@ def send( | |
| delay = ( | ||
| delay if delay else know_event and know_event.delay or 0 | ||
| ) # first the param, then the event, or 0 | ||
| internal = internal or bool(know_event and know_event.internal) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (blocking): On the async engine the first |
||
| event_instance = BoundEvent( | ||
| id=event, name=event_name, delay=delay, internal=internal, _sm=self | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -71,6 +71,31 @@ class BeaconsOfGondor(StateChart): | |||||||
| assert BeaconsOfGondor.light.delay == 50 | ||||||||
| assert BeaconsOfGondor().light.delay == 50 | ||||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nitpick (non-blocking): The bound side of
Suggested change
|
||||||||
|
|
||||||||
| @pytest.mark.parametrize("trigger", ["method", "send"]) | ||||||||
| def test_declared_internal_puts_on_the_internal_queue(self, trigger): | ||||||||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (non-blocking): Run this through |
||||||||
| class BeaconsOfGondor(StateChart): | ||||||||
| dark = State(initial=True) | ||||||||
| lit = State(final=True) | ||||||||
|
|
||||||||
| light = Event(dark.to(lit), internal=True) | ||||||||
|
|
||||||||
| sm = BeaconsOfGondor() | ||||||||
| queued = [] | ||||||||
| put = sm._engine.put | ||||||||
|
|
||||||||
| def spy(trigger_data, internal=False, **kwargs): | ||||||||
| queued.append(internal) | ||||||||
| return put(trigger_data, internal=internal, **kwargs) | ||||||||
|
|
||||||||
| sm._engine.put = spy | ||||||||
| if trigger == "method": | ||||||||
| sm.light() | ||||||||
| else: | ||||||||
| sm.send("light") | ||||||||
|
|
||||||||
| assert queued == [True] | ||||||||
| assert sm.lit.is_active | ||||||||
|
|
||||||||
| def test_derive_name_from_id(self): | ||||||||
| class StartMachine(StateChart): | ||||||||
| created = State(initial=True) | ||||||||
|
|
||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (non-blocking): Both engines collect the processing result only from external events, so
sm.go()on a declared-internal event now returnsNoneinstead of the callback result (verified:on_goreturning"go-result"givesNoneonceinternal=Trueis declared). A class-level flag changing the return contract of every caller is worth one sentence here.