pytransitions / transitions

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

Type hints for Enum #365

Closed andrewpwade closed 4 years ago

andrewpwade commented 4 years ago

Hi,

357 introduced support for enums. The docstring type hint (parsed by at least Pycharm) is list which produces a type warning in Pycharm. E.g. changing it to list or Enum removes the warning.

I'm not sure what the type hint would be for an individual state, e.g. for initial given Enum.auto etc?

aleneum commented 4 years ago

Hi @andrewpwade,

thank you for pointing that out. I fixed it for states and initial for Machine.__init__ and Machine.add_states and in several other docstrings. If you find more occurrences of this issue, give me a shout.

I'm not sure what the type hint would be for an individual state, e.g. for initial given Enum.auto etc?

Internally, we use EnumMeta to identify enumerations (classes derived from enum.Enum that can be iterated) and Enum for enum members. I have used Enum in both cases for the docstring though as the string clarifies whether an enumeration or an enum member is required. Passing single enum members where an enumeration was requested should also be no problem as state parameters are usually converted into lists if they are no list, dict or EnumMeta