Skip to content

Add type declarations for glyph_api.py#14269

Merged
mattpap merged 3 commits into
branch-3.7from
mattpap/14254_glyph_api_typing
Feb 9, 2025
Merged

Add type declarations for glyph_api.py#14269
mattpap merged 3 commits into
branch-3.7from
mattpap/14254_glyph_api_typing

Conversation

@mattpap

@mattpap mattpap commented Jan 31, 2025

Copy link
Copy Markdown
Contributor

Given limitations of Python's typing (e.g. no conditional and mapped types, no type extractors), then there will be a lot of duplication necessary to finalize this. A redesign of model type declarations may also be necessary, because typing of **kwargs has to be done using Unpack[] which only supports TypedDict.

fixes #14254

@mattpap mattpap added this to the 3.x milestone Jan 31, 2025
@bryevdv

bryevdv commented Jan 31, 2025

Copy link
Copy Markdown
Member

BTW I think this is valuable enough that it is fine to do in stages, in order to get into users' hands sooner. Even having what is here plus types for just the coordinates would be a very useful addition on its own.

A redesign of model type declarations may also be necessary, because typing of **kwargs has to be done using Unpack[] which only supports TypedDict.

I still think generating the types with a script and checking in the results in a semi-automated fashion would be fine in the short term.

@mattpap mattpap mentioned this pull request Feb 1, 2025
21 tasks
@mattpap
mattpap force-pushed the mattpap/14254_glyph_api_typing branch 2 times, most recently from 32a84e6 to 6596517 Compare February 5, 2025 21:52
@mattpap
mattpap force-pushed the mattpap/14254_glyph_api_typing branch from 6596517 to 1961a27 Compare February 9, 2025 10:14
@mattpap mattpap modified the milestones: 3.x, 3.7 Feb 9, 2025
@mattpap

mattpap commented Feb 9, 2025

Copy link
Copy Markdown
Contributor Author

This should be good enough for the first iteration, though further refinements will be required (e.g. ndarray types and shapes). I added FloatSpec and deprecated accept_* arguments in NumberSpec to simplify the mapping from properties to types.

@bryevdv bryevdv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment otherwise LGTM

Comment thread src/bokeh/core/property/dataspec.py
@mattpap
mattpap merged commit 51811aa into branch-3.7 Feb 9, 2025
@mattpap
mattpap deleted the mattpap/14254_glyph_api_typing branch February 9, 2025 22:10
@github-actions

Copy link
Copy Markdown

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators May 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for static types to glyph methods in figure' API

2 participants