ipywidgets icon indicating copy to clipboard operation
ipywidgets copied to clipboard

Type annotations

Open l0b0 opened this issue 2 years ago • 5 comments
trafficstars

Problem

Type annotations would allow developers and IDEs to easily reason about how ipywidgets is meant to be used.

Proposed Solution

Add type annotations to the point where all the Python code in this repo passes mypy inspection, and ideally mypy --strict.

Additional context

  • Example projects with mypy --strict compliance:
    • https://github.com/linz/geostore/
    • https://gitlab.com/engmark/mypy-exercises
    • https://github.com/linz/emergency-management-tools/

l0b0 avatar Feb 02 '23 22:02 l0b0

Probably a dupe of #3676.

mypy is widely used across the jupyter ecosystem, and ipywidgets is one of the "leaves" that has been hard to reason about until its upstreams are really solid.

PRs welcome, of course!

bollwyvl avatar Feb 07 '23 23:02 bollwyvl

I'm unfamiliar with this code base, and I'm only using it for a project at work, so I probably can't justify spending the time to do it myself. That said, although this is technically a dupe I'd consider it orthogonal to the docstring styling which is the core of #3676.

l0b0 avatar Feb 08 '23 02:02 l0b0

Now that mypy 1.0 is out I can pick up https://github.com/ipython/traitlets/pull/818 Again, which is 90% of the typing in ipywidgets (the traits). This is what you want I guess?

maartenbreddels avatar Feb 08 '23 06:02 maartenbreddels

orthogonal to the docstring styling

To the initial point of developers and IDEs: type hints and in-code help, as delivered from docstrings, are very tightly coupled for most IDE integrations (e.g. the language server protocol) and the jupyter messaging protocol (completion and inspection).

While moving forward on type hints would put more squiggly red lines in the editor, standardizing what a user sees when hovering over these tokens substantially improves the overall experience, which also extends to the documentation.

bollwyvl avatar Feb 08 '23 16:02 bollwyvl

This is what you want I guess?

I think the remaining 10% involve some function type annotations and adding a py.typed file

flying-sheep avatar Dec 23 '23 15:12 flying-sheep