Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Reduce API surface of internal dataclasses - #32291

Merged
iccir merged 1 commit into
matplotlib:mainfrom
QuLogic:dataclass-slots
Sep 4, 2026
Merged

Reduce API surface of internal dataclasses#32291
iccir merged 1 commit into
matplotlib:mainfrom
QuLogic:dataclass-slots

Conversation

@QuLogic

@QuLogic QuLogic commented Sep 4, 2026

Copy link
Copy Markdown
Member

PR summary

In almost all cases, these are not modified, so they can be marked frozen and with slots to make them immutable. We can also drop the __eq__ method for really internal things that are just data.

Theoretically, there is some memory savings, but I could not see much of it (possibly I just didn't test the right thing to trigger it.) With memray, I did see fewer allocations, though overall about the same memory usage.

AI Disclosure

None

PR quality check

  • Use an expressive title, e.g. "Fix title font property precedence"
  • New and changed code is tested
  • [n/a] Plotting related features are demonstrated in an example
  • [n/a] New features and API changes have release notes
  • [n/a] Documentation complies with general and docstring guidelines

@iccir iccir left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should we take this opportunity to standardize on @dataclass with an import vs @dataclasses.dataclass?

In almost all cases, these are not modified, so they can be marked
`frozen` and with `slots` to make them immutable. We can also drop the
`__eq__` method for _really_ internal things that are just data.

@timhoffm timhoffm 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.

+/-0 on standardizing the decorator

@iccir

iccir commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

+/-0 on standardizing the decorator

We can always do it in the future if we want.

@iccir
iccir merged commit 996cb9a into matplotlib:main Sep 4, 2026
36 of 37 checks passed
@QuLogic
QuLogic deleted the dataclass-slots branch September 4, 2026 22:05
@QuLogic QuLogic added this to the v3.12.0 milestone Sep 4, 2026
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.

3 participants