FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Convert _math_style_dict into an Enum. by QuLogic · Pull Request #18555 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
23 changes: 13 additions & 10 deletions lib/matplotlib/_mathtext.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Where are these two used?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Back | FazBrowse Home | New Git URL