Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Use class form of data classes#27415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
ksunden merged 2 commits intomatplotlib:mainfromQuLogic:dataclass-class
Jan 15, 2024
Merged

Conversation

QuLogic
Copy link
Member

PR summary

When these were added in#20118, we had no type annotations, so it made sense to use the functional form. Now that we do, there's no reason not to use the class form.

Also, asFontEntry has gained more methods, the functional form looks less clear.

Also, use one in the menu example.

PR checklist

@QuLogicQuLogic added this to thev3.9.0 milestoneDec 1, 2023
Comment on lines 20 to 21
labelcolor: str = 'black'
bgcolor: str = 'yellow'
Copy link
Member

Choose a reason for hiding this comment

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

Couldn't these be any matplotlib color spec type?

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

True, though I'm not sure this example ever would.

],
namespace={
'__doc__': """
@dataclasses.dataclass(frozen=True)
Copy link
Member

Choose a reason for hiding this comment

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

Making this frozen breaks JSON decoding ofFontManager. Either you have to leave this unfrozen, or you have to adaptFontManager._json_decode():

r=FontEntry.__new__(FontEntry)
r.__dict__.update(o)

MaybeFontEntry(**o) will do? Or you have to go withobject.__setattr__ similar tohttps://github.com/jsonpickle/jsonpickle/pull/397/files.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

We just need to avoid changing the element after creation, which we can do by modifying the input dictionary beforehand.

I'm not sure why we were doing__new__ and__dict__.update instead ofFontEntry(**o), but I've moved to the latter as suggested.

When these were added inmatplotlib#20118, we had no type annotations, so it madesense to use the functional form. Now that we do, there's no reason notto use the class form.Also, as `FontEntry` has gained more methods, the functional form looksless clear.
@ksundenksunden merged commitc447b60 intomatplotlib:mainJan 15, 2024
@QuLogicQuLogic deleted the dataclass-class branchJanuary 16, 2024 00:07
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@ksundenksundenksunden approved these changes

@timhoffmtimhoffmtimhoffm approved these changes

Assignees
No one assigned
Labels
backend: pdfDocumentation: APIfiles in lib/ and doc/apiDocumentation: examplesfiles in galleries/examplesMaintenance
Projects
None yet
Milestone
v3.9.0
Development

Successfully merging this pull request may close these issues.

3 participants
@QuLogic@ksunden@timhoffm

[8]ページ先頭

©2009-2025 Movatter.jp