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

Skip to content

Turn mathtext.GlueSpec into a (private) namedtuple. #16683

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

Merged
merged 1 commit into from
Mar 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions doc/api/next_api_changes/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
55 changes: 32 additions & 23 deletions lib/matplotlib/mathtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`."""

Expand All @@ -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
Expand Down