Comments (4)
Hi @owenlamont, thanks for reporting this issue.
I understand that you encountered a problem when using a keyword argument named event
in a transition action with Python State Machine. It seems that the event
keyword was silently overwritten by an internal state, causing unexpected behavior.
To address this, I'd like to point out that when you specify *args
or **kwargs
, they will still be available to you via the built-in event_data
parameter, specifically at the path event_data.trigger_data.args
or event_data.trigger_data.kwargs
. Therefore, even if you don't have control over the payload you're receiving (e.g., when processing events from a Kafka stream), you can still process events containing the keyword event
by accessing it through the EventData
dataclass.
Here's a simple code example to illustrate the use of event_data.trigger_data.kwargs
:
from statemachine.event_data import EventData
def on_await_station_load(self, event_data: EventData) -> None:
event: Event = event_data.trigger_data.kwargs["event"]
In summary, while using the event keyword might cause conflicts with Python State Machine, you can still access the data through the event_data parameter, as shown in the example. I hope this explanation clarifies your concerns. Please let me know if you have any further questions.
Does this work for you?
from python-statemachine.
Thanks, I think I did notice that eventually. It just caught me by surprise and was a bit painful to discover what was happening in PyScript without a debugger.
I take your point though that users might not have the luxury of choosing the keyword names so I know agree they shouldn't be forbidden even when clashing.
from python-statemachine.
I'll close this, I'm happy with the behaviour now you've explained it. Only possible action is maybe it is worth adding a small warning to the docs about this behaviour so it doesn't catch anyone else by surprise.
from python-statemachine.
Should mention I really like your type-hinted example above, it may be contentious with some Python devs but I'd love all the examples in the docs to be type hinted where appropriate.
from python-statemachine.
Related Issues (20)
- Finalize action after transition success or failure. HOT 1
- feature request: async callbacks HOT 3
- Incompatible with spy wrapper from pytest-mock HOT 3
- Add automation (GH action) to publish a new version on pypi HOT 1
- Simple question HOT 10
- Generate the code from PlantUML diagrams HOT 2
- Type annotations missing for `initial_state` and `final_states`; leading to linting errors with Pylint/Pyright HOT 3
- Expensive instantiation of StateMachine HOT 3
- AttributeError: object has no attribute 'model' HOT 3
- Enable Multithreading HOT 2
- [Feature request] State machine based workflow for database storage on entity state tracking HOT 1
- Action callback gets called twice when mixing definition methods HOT 1
- Check that all state transitions can reach a final state. HOT 6
- Execute a state machine from another state machine HOT 1
- Guards and conditions passed as strings really necessary? HOT 6
- ROS2, state transition not possible HOT 2
- Send a state machine over MQTT / serializing-deserializing a SM HOT 6
- Question: How can I use cond functions to gatekeep, but not fail? HOT 5
- Failed to generate a graphic image HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from python-statemachine.