cpython/Misc/NEWS.d
Miss Islington (bot) 2ce8af3cbc
bpo-42073: allow classmethod to wrap other classmethod-like descriptors (GH-27115) (GH-27162)
Patch by Erik Welch.

bpo-19072 (GH-8405) allows `classmethod` to wrap other descriptors, but this does
not work when the wrapped descriptor mimics classmethod.  The current PR fixes
this.

In Python 3.8 and before, one could create a callable descriptor such that this
works as expected (see Lib/test/test_decorators.py for examples):
```python
class A:
    @myclassmethod
    def f1(cls):
        return cls

    @classmethod
    @myclassmethod
    def f2(cls):
        return cls
```
In Python 3.8 and before, `A.f2()` return `A`. Currently in Python 3.9, it
returns `type(A)`.  This PR make `A.f2()` return `A` again.

As of GH-8405, classmethod calls `obj.__get__(type)` if `obj` has `__get__`.
This allows one to chain `@classmethod` and `@property` together.  When
using classmethod-like descriptors, it's the second argument to `__get__`--the
owner or the type--that is important, but this argument is currently missing.
Since it is None, the "owner" argument is assumed to be the type of the first
argument, which, in this case, is wrong (we want `A`, not `type(A)`).

This PR updates classmethod to call `obj.__get__(type, type)` if `obj` has
`__get__`.

Co-authored-by: Erik Welch <erik.n.welch@gmail.com>
(cherry picked from commit b83861f026)
2021-07-15 15:42:11 +02:00
..
next bpo-42073: allow classmethod to wrap other classmethod-like descriptors (GH-27115) (GH-27162) 2021-07-15 15:42:11 +02:00
3.5.0.rst
3.5.0a1.rst
3.5.0a2.rst
3.5.0a3.rst
3.5.0a4.rst
3.5.0b1.rst
3.5.0b2.rst
3.5.0b3.rst
3.5.0b4.rst
3.5.0rc1.rst
3.5.0rc2.rst
3.5.0rc3.rst
3.5.0rc4.rst
3.5.1.rst
3.5.1rc1.rst
3.5.2.rst
3.5.2rc1.rst
3.5.3.rst
3.5.3rc1.rst
3.5.4.rst
3.5.4rc1.rst
3.5.5.rst
3.5.5rc1.rst
3.6.0.rst
3.6.0a1.rst
3.6.0a2.rst
3.6.0a3.rst
3.6.0a4.rst
3.6.0b1.rst
3.6.0b2.rst
3.6.0b3.rst
3.6.0b4.rst
3.6.0rc1.rst
3.6.0rc2.rst
3.6.1.rst
3.6.1rc1.rst
3.6.2.rst
3.6.2rc1.rst
3.6.2rc2.rst
3.6.3.rst
3.6.3rc1.rst
3.6.4.rst
3.6.4rc1.rst
3.6.5.rst
3.6.5rc1.rst
3.6.6.rst
3.6.6rc1.rst
3.7.0.rst
3.7.0a1.rst
3.7.0a2.rst
3.7.0a3.rst
3.7.0a4.rst
3.7.0b1.rst
3.7.0b2.rst
3.7.0b3.rst
3.7.0b4.rst
3.7.0b5.rst
3.7.0rc1.rst
3.8.0a1.rst Fix typo in NEWS (GH23958) 2020-12-29 13:50:22 +02:00
3.8.0a2.rst
3.8.0a3.rst
3.8.0a4.rst
3.8.0b1.rst Remove duplicated words words (GH-20413) 2020-05-26 01:04:14 -07:00
3.9.0a1.rst bpo-4630: Fix errors in Lib/idlelib/NEWS.txt (GH-21594) 2020-07-23 02:06:26 -04:00
3.9.0a2.rst Correct name of bytecode in change note. (GH-22723) 2020-10-19 13:20:33 +01:00
3.9.0a3.rst Python 3.9.0a3 2020-01-24 22:05:07 +01:00
3.9.0a4.rst bpo-39572: Address typo in CHANGELOG. (GH-24999) 2021-04-22 17:35:11 -07:00
3.9.0a5.rst bpo-39871: Fix an error in a news entry (GH-21749) 2020-08-07 14:38:48 +09:00
3.9.0a6.rst Python 3.9.0a6 2020-04-27 22:44:04 +02:00
3.9.0b1.rst bpo-34956: edit and format better NEWS item in 3.9.0b1 changelog (GH-20255) 2020-05-20 05:41:26 -04:00
3.10.0a1.rst Delete PyGen_Send (#22663) 2020-10-12 12:10:42 -07:00
3.10.0a2.rst bpo-16396: fix BPO number in changelog (GH-23951) 2020-12-26 07:36:56 -08:00
3.10.0a3.rst Python 3.10.0a3 2020-12-07 19:34:10 +00:00
3.10.0a4.rst bpo-37319: Improve documentation, code and tests of randrange. (GH-19112) 2021-01-25 23:02:04 +02:00
3.10.0a5.rst Fix a typo/error in a news entry (bidst_wheel -> bdist_wheel) (GH-24284) (#26181) 2021-05-17 00:41:05 +01:00
3.10.0a6.rst Python 3.10.0a6 2021-03-01 16:45:40 +00:00
3.10.0a7.rst Fix typo in 3.10.0a7.rst (GH-25340) 2021-04-11 09:50:42 +01:00
3.10.0b1.rst Python 3.10.0b1 2021-05-03 20:34:56 +01:00
3.10.0b2.rst Python 3.10.0b2 2021-05-31 12:30:34 +01:00
3.10.0b3.rst Python 3.10.0b3 2021-06-17 11:29:18 +01:00
3.10.0b4.rst Python 3.10.0b4 2021-07-10 01:51:07 +01:00