cpython: 058cb219b3b5 (original) (raw)

--- a/Doc/library/enum.rst +++ b/Doc/library/enum.rst @@ -463,6 +463,12 @@ 2. While :class:Enum can have members 3. When another data type is mixed in, the :attr:value attribute is not the same as the enum member itself, although it is equivalant and will compare equal. +4. %-style formatting: %s and %r call :class:Enum's :meth:__str__ and

Interesting examples

--- a/Lib/enum.py +++ b/Lib/enum.py @@ -50,7 +50,6 @@ def _make_class_unpicklable(cls): cls.reduce = _break_on_call_reduce cls.module = '' - class _EnumDict(dict): """Keeps track of definition order of the enum items. @@ -182,7 +181,7 @@ class EnumMeta(type): # double check that repr and friends are not the mixin's or various # things break (such as pickle)

@@ -441,6 +440,21 @@ class Enum(metaclass=EnumMeta): return self is other return NotImplemented

+

+ def getnewargs(self): return (self.value, )

--- a/Lib/test/test_enum.py +++ b/Lib/test/test_enum.py @@ -67,6 +67,33 @@ class TestEnum(unittest.TestCase): WINTER = 4 self.Season = Season

+

+

+

+ def test_dir_on_class(self): Season = self.Season self.assertEqual( @@ -207,6 +234,77 @@ class TestEnum(unittest.TestCase): self.assertIs(type(Huh.name), Huh) self.assertEqual(Huh.name.name, 'name') self.assertEqual(Huh.name.value, 1) +

+

+

+

+

+

+

+ def test_hash(self): Season = self.Season dates = {} @@ -232,7 +330,7 @@ class TestEnum(unittest.TestCase): def test_floatenum_from_scratch(self): class phy(float, Enum):

@@ -240,7 +338,7 @@ class TestEnum(unittest.TestCase): class FloatEnum(float, Enum): pass class phy(FloatEnum):