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

Skip to content

Commit e702b06

Browse files
committed
MNT: eliminate a private Enum subclass
We used this to save duplicating two functions in string Enums, however the base class is failing mypy validation as an empty Enum class. There may be a better way to do this by silencing the checker, but if it is mypy specific we might have to play whack-a-mole with every type checker. I tried a couple permutations of moving the `Enum` inheritance around, but for meta-class reasons it appears that the enum-related special methods must be directly in the class the sub-classes Enum.
1 parent ab518bf commit e702b06

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

lib/matplotlib/_enums.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,7 @@
1414
from matplotlib import _docstring
1515

1616

17-
class _AutoStringNameEnum(Enum):
18-
"""Automate the ``name = 'name'`` part of making a (str, Enum)."""
19-
20-
def _generate_next_value_(name, start, count, last_values):
21-
return name
22-
23-
def __hash__(self):
24-
return str(self).__hash__()
25-
26-
27-
class JoinStyle(str, _AutoStringNameEnum):
17+
class JoinStyle(str, Enum):
2818
"""
2919
Define how the connection between two line segments is drawn.
3020
@@ -79,6 +69,12 @@ class JoinStyle(str, _AutoStringNameEnum):
7969
8070
"""
8171

72+
def _generate_next_value_(name, start, count, last_values):
73+
return name
74+
75+
def __hash__(self):
76+
return str(self).__hash__()
77+
8278
miter = auto()
8379
round = auto()
8480
bevel = auto()
@@ -116,7 +112,7 @@ def plot_angle(ax, x, y, angle, style):
116112
+ "}"
117113

118114

119-
class CapStyle(str, _AutoStringNameEnum):
115+
class CapStyle(str, Enum):
120116
r"""
121117
Define how the two endpoints (caps) of an unclosed line are drawn.
122118
@@ -151,6 +147,13 @@ class CapStyle(str, _AutoStringNameEnum):
151147
CapStyle.demo()
152148
153149
"""
150+
151+
def _generate_next_value_(name, start, count, last_values):
152+
return name
153+
154+
def __hash__(self):
155+
return str(self).__hash__()
156+
154157
butt = auto()
155158
projecting = auto()
156159
round = auto()

lib/matplotlib/_enums.pyi

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
from typing import cast
22
from enum import Enum
33

4-
class _AutoStringNameEnum(Enum):
5-
def __hash__(self) -> int: ...
6-
7-
class JoinStyle(str, _AutoStringNameEnum):
4+
class JoinStyle(str, Enum):
85
miter = cast(str, ...)
96
round = cast(str, ...)
107
bevel = cast(str, ...)
118
@staticmethod
129
def demo() -> None: ...
1310

14-
class CapStyle(str, _AutoStringNameEnum):
11+
class CapStyle(str, Enum):
1512
butt = cast(str, ...)
1613
projecting = cast(str, ...)
1714
round = cast(str, ...)

0 commit comments

Comments
 (0)