From 714c6c72a4fdd878df736814c83d026ef9ba2401 Mon Sep 17 00:00:00 2001 From: Elliott Sales de Andrade Date: Wed, 2 Sep 2020 03:34:01 -0400 Subject: [PATCH] Convert _math_style_dict into an Enum. --- lib/matplotlib/_mathtext.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/matplotlib/_mathtext.py b/lib/matplotlib/_mathtext.py index 6d9043c16a3b..33c3537de17a 100644 --- a/lib/matplotlib/_mathtext.py +++ b/lib/matplotlib/_mathtext.py @@ -3,6 +3,7 @@ """ from collections import namedtuple +import enum import functools from io import StringIO import logging @@ -1944,8 +1945,11 @@ class Parser: The grammar is based directly on that in TeX, though it cuts a few corners. """ - _math_style_dict = dict(displaystyle=0, textstyle=1, - scriptstyle=2, scriptscriptstyle=3) + class _MathStyle(enum.Enum): + DISPLAYSTYLE = enum.auto() + TEXTSTYLE = enum.auto() + SCRIPTSTYLE = enum.auto() + SCRIPTSCRIPTSTYLE = enum.auto() _binary_operators = set(''' + * - @@ -2798,8 +2802,7 @@ def _genfrac(self, ldelim, rdelim, rule, style, num, den): rule = float(rule) - # If style != displaystyle == 0, shrink the num and den - if style != self._math_style_dict['displaystyle']: + if style is not self._MathStyle.DISPLAYSTYLE: num.shrink() den.shrink() cnum = HCentered([num]) @@ -2848,8 +2851,8 @@ def frac(self, s, loc, toks): state.font, state.fontsize, state.dpi) num, den = toks[0] - return self._genfrac('', '', thickness, - self._math_style_dict['textstyle'], num, den) + return self._genfrac('', '', thickness, self._MathStyle.TEXTSTYLE, + num, den) def dfrac(self, s, loc, toks): assert len(toks) == 1 @@ -2860,16 +2863,16 @@ def dfrac(self, s, loc, toks): state.font, state.fontsize, state.dpi) num, den = toks[0] - return self._genfrac('', '', thickness, - self._math_style_dict['displaystyle'], num, den) + return self._genfrac('', '', thickness, self._MathStyle.DISPLAYSTYLE, + num, den) def binom(self, s, loc, toks): assert len(toks) == 1 assert len(toks[0]) == 2 num, den = toks[0] - return self._genfrac('(', ')', 0.0, - self._math_style_dict['textstyle'], num, den) + return self._genfrac('(', ')', 0.0, self._MathStyle.TEXTSTYLE, + num, den) def sqrt(self, s, loc, toks): root, body = toks[0]