summaryrefslogtreecommitdiffstats
path: root/Lib/test
diff options
context:
space:
mode:
authorEthan Furman <ethan@stoneleaf.us>2020-09-15 23:28:25 (GMT)
committerGitHub <noreply@github.com>2020-09-15 23:28:25 (GMT)
commit22415ad62555d79bd583b4a7d6a96006624a8277 (patch)
treed85eb13c71814c8169749ef10581bb98d9b678b5 /Lib/test
parent47f6ec4c09a138e9049fd245ca312842ff50ce42 (diff)
downloadcpython-22415ad62555d79bd583b4a7d6a96006624a8277.zip
cpython-22415ad62555d79bd583b4a7d6a96006624a8277.tar.gz
cpython-22415ad62555d79bd583b4a7d6a96006624a8277.tar.bz2
bpo-41789: honor object overrides in Enum classes (GH-22250)
EnumMeta double-checks that `__repr__`, `__str__`, `__format__`, and `__reduce_ex__` are not the same as `object`'s, and replaces them if they are -- even if that replacement was intentionally done in the Enum being constructed. This patch fixes that. Automerge-Triggered-By: @ethanfurman
Diffstat (limited to 'Lib/test')
-rw-r--r--Lib/test/test_enum.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py
index a909c10..865edf1 100644
--- a/Lib/test/test_enum.py
+++ b/Lib/test/test_enum.py
@@ -560,6 +560,14 @@ class TestEnum(unittest.TestCase):
self.assertFormatIsValue('{:>20}', Directional.WEST)
self.assertFormatIsValue('{:<20}', Directional.WEST)
+ def test_object_str_override(self):
+ class Colors(Enum):
+ RED, GREEN, BLUE = 1, 2, 3
+ def __repr__(self):
+ return "test.%s" % (self._name_, )
+ __str__ = object.__str__
+ self.assertEqual(str(Colors.RED), 'test.RED')
+
def test_enum_str_override(self):
class MyStrEnum(Enum):
def __str__(self):
@@ -602,7 +610,6 @@ class TestEnum(unittest.TestCase):
class Huh(MyStr, MyInt, Enum):
One = 1
-
def test_hash(self):
Season = self.Season
dates = {}