From dfec23f8fd9c3ff0aeda2f7a30c908745a72fcd3 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Fri, 6 May 2022 02:19:06 -0500 Subject: [PATCH 1/3] GH-89519: Deprecation classmethod decriptor chaining --- Doc/whatsnew/3.11.rst | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 822cb8b1f0f343..19ac8676ba638c 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -1084,6 +1084,14 @@ CPython bytecode changes Deprecated ========== +* Chaining :class:`classmethod` descriptors (introduced in :issue:`19072`) + is now deprecated. It can no longer be used to wrap other descriptors + such as :class:`property`. The core design of this feature was flawed + and caused a number of downstream problems. To "pass-through" a + :class:`classmethod`, consider using the ``__wrapped__`` attribute + that was added in Python 3.10. + (Contributed by Raymond Hettinger in :gh:`89519`.) + * Octal escapes with value larger than ``0o377`` now produce a :exc:`DeprecationWarning`. In a future Python version they will be a :exc:`SyntaxWarning` and From 99d8edd41df09dcbcf822269238dff9bf50aeed8 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Fri, 6 May 2022 02:26:31 -0500 Subject: [PATCH 2/3] Put the deprecation in the main docs. --- Doc/howto/descriptor.rst | 4 +++- Doc/library/functions.rst | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Doc/howto/descriptor.rst b/Doc/howto/descriptor.rst index 825e9d0347f5d0..5e9b110f0fe254 100644 --- a/Doc/howto/descriptor.rst +++ b/Doc/howto/descriptor.rst @@ -1349,6 +1349,8 @@ Using the non-data descriptor protocol, a pure Python version of if cls is None: cls = type(obj) if hasattr(type(self.f), '__get__'): + # This code path was added in Python 3.9 + # and was deprecated in Python 3.11. return self.f.__get__(cls, cls) return MethodType(self.f, cls) @@ -1386,7 +1388,7 @@ Using the non-data descriptor protocol, a pure Python version of The code path for ``hasattr(type(self.f), '__get__')`` was added in Python 3.9 and makes it possible for :func:`classmethod` to support chained decorators. For example, a classmethod and property could be -chained together: +chained together. In Python 3.11, this functionality was deprecated. .. testcode:: diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index cb862968970825..47b4b11cced858 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -271,6 +271,11 @@ are always available. They are listed here in alphabetical order. ``__name__``, ``__qualname__``, ``__doc__`` and ``__annotations__``) and have a new ``__wrapped__`` attribute. + .. versionchanged:: 3.11 + Class methods can no longer wrap other :term:`descriptors ` such as + :func:`property`. + + .. function:: compile(source, filename, mode, flags=0, dont_inherit=False, optimize=-1) Compile the *source* into a code or AST object. Code objects can be executed From 061d3d38fbbe8e3a0419e889662dec44cfef5516 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Fri, 6 May 2022 02:30:07 -0500 Subject: [PATCH 3/3] Add blurb --- .../2022-05-06-02-29-53.gh-issue-89519.4OfkRE.rst | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2022-05-06-02-29-53.gh-issue-89519.4OfkRE.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2022-05-06-02-29-53.gh-issue-89519.4OfkRE.rst b/Misc/NEWS.d/next/Core and Builtins/2022-05-06-02-29-53.gh-issue-89519.4OfkRE.rst new file mode 100644 index 00000000000000..1460546d148862 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2022-05-06-02-29-53.gh-issue-89519.4OfkRE.rst @@ -0,0 +1,4 @@ +Chaining classmethod descriptors (introduced in bpo-19072) is deprecated. It +can no longer be used to wrap other descriptors such as property(). The +core design of this feature was flawed, and it caused a number of downstream +problems.