-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
galleries/examples/widgets/menu.py
Outdated
labelcolor: str = 'black' | ||
bgcolor: str = 'yellow' |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 of FontManager
. Either you have to leave this unfrozen, or you have to adapt FontManager._json_decode()
:
matplotlib/lib/matplotlib/font_manager.py
Lines 937 to 938 in 379989e
r = FontEntry.__new__(FontEntry) | |
r.__dict__.update(o) |
Maybe FontEntry(**o)
will do? Or you have to go with object.__setattr__
similar to https://github.com/jsonpickle/jsonpickle/pull/397/files.
There was a problem hiding this comment.
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 of FontEntry(**o)
, but I've moved to the latter as suggested.
d1fd397
to
5d774d4
Compare
When these were added in matplotlib#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, as `FontEntry` has gained more methods, the functional form looks less clear.
5d774d4
to
5e5962f
Compare
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, as
FontEntry
has gained more methods, the functional form looks less clear.Also, use one in the menu example.
PR checklist