Skip to content

Adding type hints and ship py.typed, mypy config #6

Open
@bollwyvl

Description

@bollwyvl

Problem

While adding a simple labextension won't benefit from type checking, as soon as a REST API, widget, etc. is added, it becomes powerful tool for finding actual bugs, learning about how your code (and your dependencies' code) actually works, and particularly useful when upgrading to a new version of a well-typed upstream (e.g. jupyter_server).

Proposed Solution

Add:

  • type hints in generated .py files
  • ship py.typed
  • pyproject.toml
    • Typing :: Typed trove classifier
    • [tool.mypy] with pretty strict defaults

There are of course other typecheckers, and choice is good, but of the typed upstreams, most rely on mypy.

By just being present in a well-known location, the settings will get picked up in some IDEs (even if another typecheker is used), helping folk fix typing issues per-keystroke.

As an option, be able to add a mypy check to... whatever, whether it's make, just GHA, pre-commit, some hatch env-in-env monstrosity or whatever is suggested to folk by this template this week.

Additional context

While jupyterlab_server does ship py.typed, jupyterlab itself does not.

4.0 should probably add type hints and ship py.typed, but luckily, it isn't imported in most well-behaved extensions

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions