Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
9 changes: 6 additions & 3 deletions Doc/howto/enum.rst
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ Dataclass support
When inheriting from a :class:`~dataclasses.dataclass`,
the :meth:`~Enum.__repr__` omits the inherited class' name. For example::

>>> from dataclasses import dataclass, field
>>> @dataclass
... class CreatureDataMixin:
... size: str
Expand Down Expand Up @@ -527,7 +528,8 @@ It is possible to modify how enum members are pickled/unpickled by defining
:meth:`__reduce_ex__` in the enumeration class. The default method is by-value,
but enums with complicated values may want to use by-name::

>>> class MyEnum(Enum):
>>> import enum
>>> class MyEnum(enum.Enum):
... __reduce_ex__ = enum.pickle_by_enum_name

.. note::
Expand Down Expand Up @@ -771,7 +773,7 @@ be combined with them (but may lose :class:`IntFlag` membership::
<Perm.R|X: 5>

>>> Perm.X | 8
9
<Perm.X|8: 9>

.. note::

Expand Down Expand Up @@ -1435,8 +1437,9 @@ alias::
... GRENE = 2
...
Traceback (most recent call last):
...
...
ValueError: aliases not allowed in DuplicateFreeEnum: 'GRENE' --> 'GREEN'
Error calling __set_name__ on '_proto_member' instance 'GRENE' in 'Color'

.. note::

Expand Down
2 changes: 1 addition & 1 deletion Doc/library/enum.rst
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ Data Types
... print('today is %s' % cls(date.today().isoweekday()).name)
...
>>> dir(Weekday.SATURDAY)
['__class__', '__doc__', '__eq__', '__hash__', '__module__', 'name', 'today', 'value']
['FRIDAY', 'MONDAY', 'SATURDAY', 'SUNDAY', 'THURSDAY', 'TUESDAY', 'WEDNESDAY', '__class__', '__doc__', '__eq__', '__hash__', '__module__', 'name', 'today', 'value']

.. method:: Enum._generate_next_value_(name, start, count, last_values)

Expand Down
15 changes: 10 additions & 5 deletions Lib/test/test_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,27 @@
from io import StringIO
from pickle import dumps, loads, PicklingError, HIGHEST_PROTOCOL
from test import support
from test.support import ALWAYS_EQ
from test.support import ALWAYS_EQ, REPO_ROOT
from test.support import threading_helper
from datetime import timedelta

python_version = sys.version_info[:2]

def load_tests(loader, tests, ignore):
tests.addTests(doctest.DocTestSuite(enum))
if os.path.exists('Doc/library/enum.rst'):

lib_tests = os.path.join(REPO_ROOT, 'Doc/library/enum.rst')
if os.path.exists(lib_tests):
tests.addTests(doctest.DocFileSuite(
'../../Doc/library/enum.rst',
lib_tests,
module_relative=False,
optionflags=doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE,
))
if os.path.exists('Doc/howto/enum.rst'):
howto_tests = os.path.join(REPO_ROOT, 'Doc/howto/enum.rst')
if os.path.exists(howto_tests):
tests.addTests(doctest.DocFileSuite(
'../../Doc/howto/enum.rst',
howto_tests,
module_relative=False,
optionflags=doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE,
))
return tests
Expand Down