Description
Bug summary
The new matplotlib.colors.make_norm_from_scale
helper dynamically generates a norm class from a scale class. Currently, in the codebase, it is only used as a decorator to create "toplevel" classes (e.g., it is used to generate LogNorm from LogScale, etc.), but it can also be used within other functions to dynamically generate a norm class based on a user-given arbitrary scale (see #20752 for an example of application, which is however not necessary to understand for what follows). In the latter case, the dynamically generate class is currently not picklable (because pickling of classes relies on the existence of global names, see e.g. "classes are pickled by named reference"). It would be generally useful to get rid of this restriction, which can be done by implementing the __reduce__
protocol; there's already other examples in the codebase of dynamically generated classes that use the same mechanism).
I'm tagging this as "good first issue" because there's no API design and the eng goal is clear, but medium (perhaps hard) difficulty because it requires somewhat sophisticated understanding of the details of the pickling process.
Code for reproduction
pickle.dumps(matplotlib.colors.make_norm_from_scale(matplotlib.scale.LogitScale, matplotlib.colors.Normalize))
Actual outcome
Can't pickle <class 'matplotlib.colors.Normalize'>: it's not the same object as matplotlib.colors.Normalize
(Note the additional confusion here: there's two classes that are both named matplotlib.colors.Normalize
-- the original one and the dynamically generated one -- but they are different.)
Expected outcome
A correct round-trippable pickle.
Operating system
No response
Matplotlib Version
master (unreleased, pre 3.5)
Matplotlib Backend
No response
Python version
No response
Jupyter version
No response
Other libraries
No response
Installation
source
Conda channel
No response