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

Add py.typed to enable type checking #17

Open
alexlukas opened this issue Mar 25, 2024 · 4 comments
Open

Add py.typed to enable type checking #17

alexlukas opened this issue Mar 25, 2024 · 4 comments

Comments

@alexlukas
Copy link

I was a little too fast and created some stubs for the typeshed project in order to allow for type checking code using this library according to PEP 561 (see here for the pull request). However, I was made aware that most of this library is already typed, so to enable type checking for nanoleafapi, all one has to do is

  • add an empty py.typed file
  • add the following to setup.py
setup(
    ...,
    package_data = {
        'nanoleafapi': ['py.typed'],
    },
    ...,
    )

This would explicitly allow type checking for nanoleafapi, e.g. in VS Code.

@MylesMor
Copy link
Owner

Hi, appreciate you opening this issue here! I can definitely see about adding this tomorrow. Since this is new to me, would you know how I can test to make sure it works before I publish the change to the package?

@AlexWaygood
Copy link

Hey @MylesMor — here's a possible way of testing this kind of thing in a GitHub Actions workflow:

jobs:
  check-pep561-compliance:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
        with:
          path: invoke
      - uses: actions/setup-python@v4
        with:
          python-version: "3.11"
      - run: |
          pip install mypy
          pip install ./nanoleafapi
          mkdir newdir
          cd newdir
          mypy -c "import nanoleafapi"

The job should fail with mypy errors without the py.typed file, but pass if the py.typed file has been properly added (including the packaging changes @alexlukas mentioned above, which are necessary to ensure that the file gets included in the wheel)

@MylesMor
Copy link
Owner

Thanks, appreciate this! Unfortunately was super busy today but will hopefully get around to this tomorrow.

@JelleZijlstra
Copy link

Friendly bump (got here because the related typeshed PR is still open).

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

4 participants