Skip to content

bpo-43162: [Enum] update docs, renable doc tests #24487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 3, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 6 additions & 5 deletions Doc/library/enum.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1222,17 +1222,18 @@ Private names are not converted to Enum members, but remain normal attributes.
:class:`Enum` members are instances of their :class:`Enum` class, and are
normally accessed as ``EnumClass.member``. In Python versions ``3.5`` to
``3.9`` you could access members from other members -- this practice was
discouraged, and in ``3.10`` :class:`Enum` has returned to not allowing it::
discouraged, and in ``3.12`` :class:`Enum` will return to not allowing it,
while in ``3.10`` and ``3.11`` it will raise a :exc:`DeprecationWarning`::

>>> class FieldTypes(Enum):
... name = 0
... value = 1
... size = 2
...
>>> FieldTypes.value.size
Traceback (most recent call last):
...
AttributeError: FieldTypes: no attribute 'size'
>>> FieldTypes.value.size # doctest: +SKIP
DeprecationWarning: accessing one member from another is not supported,
and will be disabled in 3.12
<FieldTypes.size: 2>

.. versionchanged:: 3.5
.. versionchanged:: 3.10
Expand Down
2 changes: 1 addition & 1 deletion Lib/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def __get__(self, instance, ownerclass=None):
import warnings
warnings.warn(
"accessing one member from another is not supported, "
" and will be disabled in 3.11",
" and will be disabled in 3.12",
DeprecationWarning,
stacklevel=2,
)
Expand Down
6 changes: 3 additions & 3 deletions Lib/test/test_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

def load_tests(loader, tests, ignore):
tests.addTests(doctest.DocTestSuite(enum))
if os.path.exists('../../Doc/library/enum.rst'):
if os.path.exists('Doc/library/enum.rst'):
tests.addTests(doctest.DocFileSuite(
'../../Doc/library/enum.rst',
optionflags=doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE,
Expand Down Expand Up @@ -2186,7 +2186,7 @@ class Private(Enum):
self.assertEqual(Private._Private__major_, 'Hoolihan')

@unittest.skipUnless(
sys.version_info[:2] == (3, 10),
sys.version_info[:2] < (3, 12),
'member-member access now raises an exception',
)
def test_warning_for_member_from_member_access(self):
Expand All @@ -2198,7 +2198,7 @@ class Di(Enum):
self.assertIs(Di.NO, nope)

@unittest.skipUnless(
sys.version_info[:2] > (3, 10),
sys.version_info[:2] >= (3, 12),
'member-member access currently issues a warning',
)
def test_exception_for_member_from_member_access(self):
Expand Down