Title: [3.10] bpo-42073: allow classmethod to wrap other classmethod-like descriptors (GH-27115) by miss-islington · Pull Request #27162 · python/cpython · GitHub
Open Graph Title: [3.10] bpo-42073: allow classmethod to wrap other classmethod-like descriptors (GH-27115) by miss-islington · Pull Request #27162 · python/cpython
X Title: [3.10] bpo-42073: allow classmethod to wrap other classmethod-like descriptors (GH-27115) by miss-islington · Pull Request #27162 · python/cpython
Description: 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): 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 b83861f) Co-authored-by: Łukasz Langa lukasz@langa.pl https://bugs.python.org/issue42073
Open Graph Description: 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...
X Description: 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...
Opengraph URL: https://github.com/python/cpython/pull/27162
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:260f0bba-a867-148e-0e20-6b82fad33698 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | DB80:183565:12AF78:17C83E:6A5AB268 |
| html-safe-nonce | 8fc14ac7accf70aeb17fd9c754028b94c06479a5edc37d86fbe3ca30e5460e7d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQjgwOjE4MzU2NToxMkFGNzg6MTdDODNFOjZBNUFCMjY4IiwidmlzaXRvcl9pZCI6IjI5NzA2NjM0OTcyOTU5MTkxMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 244808cb5e4e4a802ec1fc21c0f57b7172836bc90158053b1fcd96fe13e641d3 |
| hovercard-subject-tag | pull_request:690710605 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/python/cpython/pull/27162/files |
| twitter:image | https://avatars.githubusercontent.com/u/31488909?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/31488909?s=400&v=4 |
| og:image:alt | 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... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 2702febe50e53f9152dda552dc2049a5eb182778b2655abd5b8619e82e899b4a |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | c0211a077f9b056c5e115f996d9049616d85c3b5 |
| ui-target | canary-1 |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width