diff --git a/doc/api/next_api_changes/deprecations.rst b/doc/api/next_api_changes/deprecations.rst index 9e9fc0a6f40e..d33d6d643908 100644 --- a/doc/api/next_api_changes/deprecations.rst +++ b/doc/api/next_api_changes/deprecations.rst @@ -242,3 +242,8 @@ The following related APIs are also deprecated: ``matplotlib.test(recursionlimit=...)`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The *recursionlimit* parameter of ``matplotlib.test`` is deprecated. + +mathtext glues +~~~~~~~~~~~~~~ +The *copy* parameter of ``mathtext.Glue`` is deprecated (the underlying glue +spec is now immutable). ``mathtext.GlueSpec`` is deprecated. diff --git a/lib/matplotlib/mathtext.py b/lib/matplotlib/mathtext.py index ccd033850de8..d05241aef528 100644 --- a/lib/matplotlib/mathtext.py +++ b/lib/matplotlib/mathtext.py @@ -1849,41 +1849,57 @@ def __init__(self, state): Rule.__init__(self, thickness, np.inf, np.inf, state) +_GlueSpec = namedtuple( + "_GlueSpec", "width stretch stretch_order shrink shrink_order") +_GlueSpec._named = { + 'fil': _GlueSpec(0., 1., 1, 0., 0), + 'fill': _GlueSpec(0., 1., 2, 0., 0), + 'filll': _GlueSpec(0., 1., 3, 0., 0), + 'neg_fil': _GlueSpec(0., 0., 0, 1., 1), + 'neg_fill': _GlueSpec(0., 0., 0, 1., 2), + 'neg_filll': _GlueSpec(0., 0., 0, 1., 3), + 'empty': _GlueSpec(0., 0., 0, 0., 0), + 'ss': _GlueSpec(0., 1., 1, -1., 1), +} + + class Glue(Node): """ Most of the information in this object is stored in the underlying - `GlueSpec` class, which is shared between multiple glue objects. + ``_GlueSpec`` class, which is shared between multiple glue objects. (This is a memory optimization which probably doesn't matter anymore, but it's easier to stick to what TeX does.) """ + @cbook.deprecated("3.3") + @property + def glue_subtype(self): + return "normal" + + @cbook._delete_parameter("3.3", "copy") def __init__(self, glue_type, copy=False): Node.__init__(self) - self.glue_subtype = 'normal' if isinstance(glue_type, str): - glue_spec = GlueSpec.factory(glue_type) - elif isinstance(glue_type, GlueSpec): + glue_spec = _GlueSpec._named[glue_type] + elif isinstance(glue_type, _GlueSpec): glue_spec = glue_type else: raise ValueError("glue_type must be a glue spec name or instance") - if copy: - glue_spec = glue_spec.copy() - self.glue_spec = glue_spec + self.glue_spec = glue_spec def shrink(self): Node.shrink(self) if self.size < NUM_SIZE_LEVELS: - if self.glue_spec.width != 0.: - self.glue_spec = self.glue_spec.copy() - self.glue_spec.width *= SHRINK_FACTOR + g = self.glue_spec + self.glue_spec = g._replace(width=g.width * SHRINK_FACTOR) def grow(self): Node.grow(self) - if self.glue_spec.width != 0.: - self.glue_spec = self.glue_spec.copy() - self.glue_spec.width *= GROW_FACTOR + g = self.glue_spec + self.glue_spec = g._replace(width=g.width * GROW_FACTOR) +@cbook.deprecated("3.3") class GlueSpec: """See `Glue`.""" @@ -1908,16 +1924,9 @@ def factory(cls, glue_type): return cls._types[glue_type] -GlueSpec._types = { - 'fil': GlueSpec(0., 1., 1, 0., 0), - 'fill': GlueSpec(0., 1., 2, 0., 0), - 'filll': GlueSpec(0., 1., 3, 0., 0), - 'neg_fil': GlueSpec(0., 0., 0, 1., 1), - 'neg_fill': GlueSpec(0., 0., 0, 1., 2), - 'neg_filll': GlueSpec(0., 0., 0, 1., 3), - 'empty': GlueSpec(0., 0., 0, 0., 0), - 'ss': GlueSpec(0., 1., 1, -1., 1) -} +with cbook._suppress_matplotlib_deprecation_warning(): + GlueSpec._types = {k: GlueSpec(**v._asdict()) + for k, v in _GlueSpec._named.items()} # Some convenient ways to get common kinds of glue