Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve static typing #35

Open
2 tasks
NixBiks opened this issue May 29, 2021 · 4 comments
Open
2 tasks

Improve static typing #35

NixBiks opened this issue May 29, 2021 · 4 comments

Comments

@NixBiks
Copy link
Collaborator

NixBiks commented May 29, 2021

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
Copy link
Collaborator Author

NixBiks commented May 29, 2021

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+

@davidkpiano
Copy link
Member

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.

@NixBiks
Copy link
Collaborator Author

NixBiks commented May 29, 2021

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: microsoft/pylance-release#654

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

@NixBiks NixBiks mentioned this issue May 29, 2021
7 tasks
NixBiks added a commit that referenced this issue May 29, 2021
Closes #33

Created new issue to resolve all type issues: #35
Created new issue to add the documentation in another PR: #36
@NixBiks NixBiks changed the title Add static type checker to CI and fix current type issues Improve static typing Jun 1, 2021
@NixBiks
Copy link
Collaborator Author

NixBiks commented Oct 8, 2021

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; microsoft/pylance-release#654 and this: https://github.com/microsoft/pylance-release/releases/tag/2021.9.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants