xstate-python icon indicating copy to clipboard operation
xstate-python copied to clipboard

Improve static typing

Open NixBiks opened this issue 4 years ago • 4 comments

This is a task originally made for PR #34 but I decided to make it into its own issue instead, since it will take some effort to do proper typing in the package.

  • [ ] Make sure poetry run mypy -p xstate runs without errors
  • [ ] Add mypy to .github/workflows/pull_request.yaml in the code quality section

NixBiks avatar May 29 '21 13:05 NixBiks

I think it would be great to add something like the following type

import typing as t
from typing_extensions import TypedDict  # only available in typing from py3.8+


class Config(TypedDict):
    id: t.Optional[str]
    entry: ...
    exit: ...
    states: ...
    on: ...
    type: ...
    data: ...
    onDone: ...
    initial: ...

Then you get auto complete suggestions when using the config object and IDE's should warn you if you try to make a config that isn't valid.

What python versions do we wish to support? No need for typing_extensions if we look at python 3.8+

NixBiks avatar May 29 '21 14:05 NixBiks

What python versions do we wish to support? No need for typing_extensions if we look at python 3.8+

We probably want to support 3.x versions of Python (whatever this cut-off is), since I imagine the majority of Python devs are still on an older version.

davidkpiano avatar May 29 '21 15:05 davidkpiano

To get improved auto suggestions when creating config in VS Code (when above is implemented) we'd need this issue to be resolved in Pylance: https://github.com/microsoft/pylance-release/issues/654

They prioritise by upvotes so if you want better autocomplete for XState in python then please give it a vote.

NixBiks avatar May 29 '21 15:05 NixBiks

Pyright released a new version that enables autocomplete for TypedDict in VS Code if people use Pylance (which I assume anyone writing python in vs code pretty much do).

See this for details; https://github.com/microsoft/pylance-release/issues/654 and this: https://github.com/microsoft/pylance-release/releases/tag/2021.9.4

NixBiks avatar Oct 08 '21 18:10 NixBiks