Skip to content

Feature: Typing Part 1 - scaffolding, basic vocabulary - #5920

Open
KoolADE85 wants to merge 17 commits into
mainfrom
typing/1-scaffolding-vocabulary-colors
Open

KoolADE85 wants to merge 17 commits into
mainfrom
typing/1-scaffolding-vocabulary-colors

Conversation

@KoolADE85

@KoolADE85 KoolADE85 commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

This PR adds the scaffolding and basic vocabulary for types in Python.
It is the first of several PRs on this topic.

What's Added

  • py.typed added so that type checkers use our annotations
  • plotly.types introduces a single import location for every type
    • hand-written types in _common.py
    • generated types in _generated/ (loaded lazily so imports stay fast)
  • codegen/types implements types in the generated code

While the diff looks large, it is mostly 2 mechanical edits:

  1. Generated files get an __all__ list for type checkers
  2. The colour palettes are all annotated as colours

What's Tested

  • python commands.py typecheck checks the internal code for type accuracy AND checks that "example usage" code in tests/test_typing does not produce type issues for end-users.
  • .github/workflows/check-types.yml runs that command on Python 3.10 to 3.14
  • During development, I added tests/test_core/test_type_suppressions to fail if my agent tries any tricks to suppress/disable checking on any line. It is temporary and I intend to delete it by the PR that finishes the implementation.

User Impact

Users can now do this:

from plotly.types import Color, ArrayLike

palette: ArrayLike[Color] = plotly.colors.sequential.Viridis

Noteworthy: this PR is about adding annotations and is NOT to change any runtime behaviour of plotly.py.

KoolADE85 and others added 17 commits November 25, 2026 09:32
- Ship plotly/py.typed and add typing_extensions as a runtime dependency
- Pin mypy and pyright in dev_core; both run in strict mode over an
  explicit module list configured in pyproject.toml
- Add plotly.types with the hand-written vocabulary: Color, Colorscale,
  Datum, DataFrame, and the ArrayLike protocol
- Add tests/test_typing: positive cases checked by both checkers,
  negative cases asserted line by line against both checkers, a check
  that the typed surface carries no suppression directive, and a
  pyright --verifytypes completeness ratchet run against the built wheel
- Add the check-types workflow

Part of #1103

Co-Authored-By: Claude <noreply@anthropic.com>
…el type tests

- Generate plotly/types/_generated.py from plot-schema.json: TraceType, the
  Trace union of trace classes, and the common enum aliases (Calendar, Dash,
  AxisType, XRef, YRef, PatternShape, TransitionEasing) through the anchor
  table ported from plotly.js tasks/generate_schema_types.mjs
- Emit __all__ inside the TYPE_CHECKING branch of every generated
  __init__.py so pyright and mypy see the re-exports the runtime builds with
  relative_import; without it pyright reports go.Figure as a private import
  against the installed wheel
- Ship _plotly_utils/py.typed as well: PEP 561 markers are per top-level
  package, and mypy treated everything plotly re-exports from _plotly_utils
  as untyped
- Re-export the colour palettes explicitly (import x as x) so strict mypy
  sees plotly.colors.sequential and friends; plotly/colors joins the module
  list
- Test the wheel as installed users see it: pyright in standard mode reports
  no errors and strict mypy reports nothing but no-untyped-call on a smoke
  script; re-baseline the completeness ratchet at 0.248 now that __all__
  exposes every generated class to --verifytypes

Part of #1103

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
- Annotate every palette constant in the seven palette modules as
  list[Color], so hovers and error messages show the Color alias instead
  of the inferred list[str]
- Quote the annotations and import Color under a private _TYPE_CHECKING
  alias: _swatches() treats every public global of a palette module as a
  palette, so neither a __future__ import nor a bare TYPE_CHECKING name can
  be added to those modules
- Test that pyright prints list[Color] for a palette from each module,
  including a reversed _r copy, against the built wheel

Part of #1103

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
- Add attribute docstrings to Color, Colorscale, Datum, and DataFrame, and a
  class docstring to ArrayLike; pyright and basedpyright show them when
  hovering the alias name at any use site
- Add a minimal language-server client to tests/test_typing and test that
  hovering each vocabulary type through plotly.types shows its explanation

Part of #1103

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
… 3.10

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@camdecoster camdecoster self-assigned this Dec 1, 2026
@KoolADE85 KoolADE85 added the no-changelog A changelog entry is not required for this PR label Dec 2, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-changelog A changelog entry is not required for this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants