pytransitions / transitions

A lightweight, object-oriented finite state machine implementation in Python with many extensions
MIT License
5.52k stars 525 forks source link

Add support for StrEnum #373

Closed chrisjbremner closed 4 years ago

chrisjbremner commented 4 years ago

Enum allows you to subclass it with additional mixins to create custom Enums that act in a similar fashion to what you are mixing in. For example, you can create an IntEnum which allows the enum to be used like an int. Similarly, you can make a StrEnum to do string comparisons.

Using a StrEnum almost works with the existing code base, but there's one small if statement that incorrectly catches StrEnums but not regular Enums, which I fix in this PR. I also included a test that would fail without this code change, but succeeds after.

coveralls commented 4 years ago

Coverage Status

Coverage decreased (-0.2%) to 98.333% when pulling c4dae18c7f4021e8fb30775759e971d1528b3f4d on chrisjbremner:master into 02076d3f259efd1a2c066a823547ecd7083a49b7 on pytransitions:master.

chrisjbremner commented 4 years ago

@aleneum I also found that the diagramming extensions did not work when using Enums for states (because it sometimes referred to each state by the Enum's name, and other times by just the Enum itself), so I attempted to fix that as well in my most recent commit.

chrisjbremner commented 4 years ago

Looks like my second commit broke some tests, I will fix that when I get a chance.

chrisjbremner commented 4 years ago

Closing, as this was fixed in https://github.com/pytransitions/transitions/pull/357