Skip to content

TYP: Use new generic type syntax from PEP 695#31923

Merged
timhoffm merged 2 commits into
matplotlib:mainfrom
QuLogic:generic-types
Jun 25, 2026
Merged

TYP: Use new generic type syntax from PEP 695#31923
timhoffm merged 2 commits into
matplotlib:mainfrom
QuLogic:generic-types

Conversation

@QuLogic

@QuLogic QuLogic commented Jun 19, 2026

Copy link
Copy Markdown
Member

PR summary

This is now available with our minimum Python 3.12, and allows doing away with TypeVar, TypeAlias, and ParamSpec.

Note, this is based on #31920.

AI Disclosure

PR checklist

QuLogic added 2 commits June 24, 2026 16:24
We can do this now that we require Python 3.12.
No longer do we need to define private `TypeVar` variables with
semi-unique names, but instead a function/class/method-local type can be
created. As these are now local, I have dropped the leading underscores.
def cla(self) -> None: ...

class ArtistList(Sequence[_T]):
class ArtistList[T: Artist](Sequence[T]):

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.

Is parametrization necessary here? I think we can direktly replace T -> Artist.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, each of the sublists (.collections, .lines, etc.) is specialized with a specific Artist subclass.

@timhoffm timhoffm merged commit 5a33910 into matplotlib:main Jun 25, 2026
38 of 41 checks passed
@QuLogic QuLogic deleted the generic-types branch June 25, 2026 16:52
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