Giter Site home page Giter Site logo

Comments (4)

fgmacedo avatar fgmacedo commented on May 29, 2024 1

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.

owenlamont avatar owenlamont commented on May 29, 2024 1

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.

owenlamont avatar owenlamont commented on May 29, 2024 1

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.

owenlamont avatar owenlamont commented on May 29, 2024 1

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.