From 17383150cbc9703bad7c098f6aeae75947efcdef Mon Sep 17 00:00:00 2001 From: Ethan Furman Date: Mon, 8 Feb 2021 18:42:12 -0800 Subject: [PATCH 1/2] [Enum] update docs, renable doc tests --- Doc/library/enum.rst | 11 ++++++----- Lib/test/test_enum.py | 2 +- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Doc/library/enum.rst b/Doc/library/enum.rst index b7f269464e79453..dffbedc7158d78c 100644 --- a/Doc/library/enum.rst +++ b/Doc/library/enum.rst @@ -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.11`` :class:`Enum` will return to not allowing it, +while in ``3.10`` 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.11 + .. versionchanged:: 3.5 .. versionchanged:: 3.10 diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py index 3982d1d6430430e..4dc51aa51269008 100644 --- a/Lib/test/test_enum.py +++ b/Lib/test/test_enum.py @@ -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, From 8645da195595aff1df8881a6fb5fa11e0d903e56 Mon Sep 17 00:00:00 2001 From: Ethan Furman Date: Tue, 2 Mar 2021 10:53:28 -0800 Subject: [PATCH 2/2] make deprecation warning active for two releases --- Doc/library/enum.rst | 6 +++--- Lib/enum.py | 2 +- Lib/test/test_enum.py | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Doc/library/enum.rst b/Doc/library/enum.rst index dffbedc7158d78c..73b77cbc671cd52 100644 --- a/Doc/library/enum.rst +++ b/Doc/library/enum.rst @@ -1222,8 +1222,8 @@ 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.11`` :class:`Enum` will return to not allowing it, -while in ``3.10`` it will raise a :exc:`DeprecationWarning`:: +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 @@ -1232,7 +1232,7 @@ while in ``3.10`` it will raise a :exc:`DeprecationWarning`:: ... >>> FieldTypes.value.size # doctest: +SKIP DeprecationWarning: accessing one member from another is not supported, - and will be disabled in 3.11 + and will be disabled in 3.12 .. versionchanged:: 3.5 diff --git a/Lib/enum.py b/Lib/enum.py index 55299c578824463..84c7b0dc2afbef7 100644 --- a/Lib/enum.py +++ b/Lib/enum.py @@ -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, ) diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py index 4dc51aa51269008..69392e01faacd5d 100644 --- a/Lib/test/test_enum.py +++ b/Lib/test/test_enum.py @@ -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): @@ -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):