Skip to content

TYP: Add type information to the data parameter of plot functions#31482

Open
timhoffm wants to merge 2 commits intomatplotlib:mainfrom
timhoffm:typ-data
Open

TYP: Add type information to the data parameter of plot functions#31482
timhoffm wants to merge 2 commits intomatplotlib:mainfrom
timhoffm:typ-data

Conversation

@timhoffm
Copy link
Copy Markdown
Member

@timhoffm timhoffm commented Apr 9, 2026

Closes #31480.

We type all as Mapping[str, Any]. Some uses have actually a broad range of supported types because they map quite a number of parameters.

Even for the ones which we know all parameters supported by data are ArrayLike, typing as Mapping[str, ArrayLike] may be too risky, as the user may have more keys in the data structure, which we don't use, but their values would be type checked and could be anything.

Closes matplotlib#31480.

We type all as `Mapping[str, Any]`. Some uses have actually a broad
range of supported types because they map quite a number of parameters.

Even for the ones which we know all parameters supported by `data` are
ArrayLike, typing as `Mapping[str, ArrayLike]` may be too risky, as the
user may have more keys in the data structure, which we don't use, but
their values would be type checked and could be anything.
@tacaswell
Copy link
Copy Markdown
Member

I suspect we are using a different version of black to format the boilerplate output.

@QuLogic
Copy link
Copy Markdown
Member

QuLogic commented Apr 10, 2026

See also #25634.

@QuLogic QuLogic requested a review from ksunden April 10, 2026 07:14
@timhoffm
Copy link
Copy Markdown
Member Author

Indeed, this PR does not solve everything. It only removes the complaint on untyped data. It does not solve the type interdependency between data and x, y ...

Typechecking of vlines('x', 'y1', 'y2', data=...) will still fail as x cannot be a str. OTOH independently have the issue that these could be strings even without data due to categorical units. So if we want unit support in type checking, we anyway have to accept strings.

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.

[ENH]: Axes.plot typing

3 participants