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

Skip to content

Convert _math_style_dict into an Enum. #18555

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
Sep 25, 2020
Merged
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
23 changes: 13 additions & 10 deletions lib/matplotlib/_mathtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

from collections import namedtuple
import enum
import functools
from io import StringIO
import logging
Expand Down Expand Up @@ -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()

Comment on lines +1951 to 1953
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where are these two used?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, apparently nowhere. My guess is they were defined for compatibility with TeX, but never implemented. Looking at commit messages of #8151, I think that was the author's goal but maybe never got back to it.

_binary_operators = set('''
+ * -
Expand Down Expand Up @@ -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])
Expand Down Expand Up @@ -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
Expand All @@ -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]
Expand Down