Skip to content

TYP: Fix some Legend-related typing#32111

Open
QuLogic wants to merge 3 commits into
matplotlib:mainfrom
QuLogic:legend-typing
Open

TYP: Fix some Legend-related typing#32111
QuLogic wants to merge 3 commits into
matplotlib:mainfrom
QuLogic:legend-typing

Conversation

@QuLogic

@QuLogic QuLogic commented Jul 24, 2026

Copy link
Copy Markdown
Member

PR summary

Specifically, type the rest of legend_handler.pyi, and fix types for Artist.get_label and PackerBase.__init__.

AI Disclosure

None

PR checklist

QuLogic added 3 commits July 24, 2026 03:40
Namely, 1) add a `Protocol` for `HandlerPatch's callable, as default
arguments cannot be represented by plain `Callable`; 2) propagate kwargs
for `__init__` with a `TypedDict` (but note that I manually typed kwargs
for `HandlerNpoints` subclasses as `TypedDict` entries are not allowed
to duplicate explicit kwargs and many of them have at least one); 3) add
a few missed parameter types.
The input to `Artist.set_label` is cast to a `str` immediately (unless
`None`) when saved, so getting it is always `str`, not `object`.
It takes any `Artist` and `list` is invariant, so switch `Sequence`.
Comment thread lib/matplotlib/axis.pyi
def get_tick_padding(self) -> float: ...
def get_gridlines(self) -> list[Line2D]: ...
def get_label(self) -> Text: ...
def get_label(self) -> Text: ... # type: ignore[override]

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.

On a side note, this inconsistent use of label is discussed in #29422.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants