transitions icon indicating copy to clipboard operation
transitions copied to clipboard

mypy support?

Open Henddher opened this issue 2 years ago • 1 comments

Hi, great library!!!!

Any plans to add support for mypy?

I'm using the library but missing types trigger this error

error: Skipping analyzing "transitions": module is installed, but missing library stubs or py.typed marker  [import]

Henddher avatar May 30 '22 17:05 Henddher

Same for us, but with asyncio extension. Really looking forward to mypy support

jellyfish-tech avatar Aug 06 '22 12:08 jellyfish-tech

transitions 0.9.0 has been published to PyPI and include typing stub files. Since transitions allows rather arbitrary argument types in functions and constructors there might be some false positive typing warnings. I personally would expect false negatives though. My goal for 0.9.0 was to satisfy mypy in 'common' usage scenarios without extensive typing of state and transition definitions. Since nested configurations are often not accurately typed by mypy I opted for rather generic fallback types. Depending on your IDE this might lead to a vast amount of suggested type options. I am looking forward to community feedback to adjust this in upcoming releases.

For now I hope this makes your work slightly easier.

aleneum avatar Sep 02 '22 10:09 aleneum

Thank you @aleneum

Will have to update to 0.9.0 and see how it plays out.

Henddher avatar Sep 20 '22 00:09 Henddher

I am using 0.9.0 but cant seem to have type definitions work for trigger methods that are generated at run time

vaidik avatar Oct 12 '23 17:10 vaidik

Hello @vaidik,

cant seem to have type definitions work for trigger methods that are generated at run time

as far as I know this cannot be done with a static code analysis and type annotation. DocMachine might be useful. Alternatively, you could define your trigger methods on your model in advance for IDEs and code checkers to pick up and use OverrideMachine to allow transitions to override these methods during runtime. If you have a more elegant solution to deal with type checking and dynamic methods/attributes let me know.

aleneum avatar Oct 13 '23 07:10 aleneum