Title: [3.9] bpo-42073: allow classmethod to wrap other classmethod-like descriptors. by eriknw · Pull Request #22757 · python/cpython · GitHub
Open Graph Title: [3.9] bpo-42073: allow classmethod to wrap other classmethod-like descriptors. by eriknw · Pull Request #22757 · python/cpython
X Title: [3.9] bpo-42073: allow classmethod to wrap other classmethod-like descriptors. by eriknw · Pull Request #22757 · python/cpython
Description: bpo-19072 (#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 #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__. This PR is targeting Python 3.9 branch, because I think this is a bug fix. I can also target master (3.10). I'm not really sure where to add a note of this change. https://bugs.python.org/issue42073
Open Graph Description: bpo-19072 (#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 coul...
X Description: bpo-19072 (#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 coul...
Opengraph URL: https://github.com/python/cpython/pull/22757
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:49654edf-fc97-159a-afc5-8db08259a11b |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 8C30:91E8C:1837F58:22C6A31:6A5A379C |
| html-safe-nonce | 85fccba1f5be5b2bbc04481347924b757fe81cd2d599c54383c58e91f1772881 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4QzMwOjkxRThDOjE4MzdGNTg6MjJDNkEzMTo2QTVBMzc5QyIsInZpc2l0b3JfaWQiOiI1MDY3NTIwMzA1MzE0NTQzNTE2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | b94cf04ee9b6e8c80c9ee8a29ce197ff721e42ac4cc07913ca5faaff0b4bb6f1 |
| hovercard-subject-tag | pull_request:505573063 |
| 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/22757/files |
| twitter:image | https://avatars.githubusercontent.com/u/2058401?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/2058401?s=400&v=4 |
| og:image:alt | bpo-19072 (#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 coul... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 19c67ad7579d2401ff06e88a32ef45460fbb40fab3191c7f7582d5e166f326fc |
| 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 | e618485bff22dab2ef1ffb4e34e4e6626688df69 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width