Title: PEP 649: `functools.update_wrapper` implementation · Issue #124342 · python/cpython · GitHub
Open Graph Title: PEP 649: `functools.update_wrapper` implementation · Issue #124342 · python/cpython
X Title: PEP 649: `functools.update_wrapper` implementation · Issue #124342 · python/cpython
Description: The current implementation of PEP-649 and PEP-749 on main simply copies functions' __annotate__ in functools.update_wrapper (and thence functools.wraps): >>> def f(x: y): pass ... >>> from functools import wraps >>> @wraps(f) ... def g(x...
Open Graph Description: The current implementation of PEP-649 and PEP-749 on main simply copies functions' __annotate__ in functools.update_wrapper (and thence functools.wraps): >>> def f(x: y): pass ... >>> from functool...
X Description: The current implementation of PEP-649 and PEP-749 on main simply copies functions' __annotate__ in functools.update_wrapper (and thence functools.wraps): >>> def f(x: y): pass ... >...
Opengraph URL: https://github.com/python/cpython/issues/124342
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"PEP 649: `functools.update_wrapper` implementation","articleBody":"The current implementation of PEP-649 and PEP-749 on main simply copies functions' `__annotate__` in `functools.update_wrapper` (and thence `functools.wraps`):\r\n\r\n```\r\n\u003e\u003e\u003e def f(x: y): pass\r\n... \r\n\u003e\u003e\u003e from functools import wraps\r\n\u003e\u003e\u003e @wraps(f)\r\n... def g(x): pass\r\n... \r\n\u003e\u003e\u003e g.__annotate__ is f.__annotate__\r\nTrue\r\n```\r\n\r\nBut as @ncoghlan pointed out (https://github.com/larryhastings/co_annotations/issues/21, https://discuss.python.org/t/pep-749-implementing-pep-649/54974/4), this may not be what we want in the case where the original function's `__annotations__` have been modified:\r\n\r\n```\r\n\u003e\u003e\u003e def f(x: int): pass\r\n... \r\n\u003e\u003e\u003e f.__annotations__[\"x\"] = 42\r\n\u003e\u003e\u003e @wraps(f)\r\n... def g(x): pass\r\n... \r\n\u003e\u003e\u003e f.__annotations__\r\n{'x': 42}\r\n\u003e\u003e\u003e g.__annotations__\r\n{'x': \u003cclass 'int'\u003e}\r\n```\r\n\r\nAlyssa therefore suggests making `update_wrapper` create a wrapper `__annotate__` function that looks in the original function's `__annotations__` first. This doesn't fit neatly into `update_wrapper`'s current structure of WRAPPER_ASSIGNMENTS and WRAPPER_UPDATES, so we should add a third bucket, maybe WRAPPER_DELEGATIONS.\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-124346\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/JelleZijlstra","@type":"Person","name":"JelleZijlstra"},"datePublished":"2024-09-23T14:49:20.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":5},"url":"https://github.com/124342/cpython/issues/124342"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:30d4b650-2065-dcf7-5ef8-cb1ba5f5d31e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C8C2:9124A:3C47CA7:4F20FFF:696BA7B3 |
| html-safe-nonce | 47942e7b6bec5f3a8a2ace2ff2bf7134b55ba1a5628b241b3de2cdd6123f4127 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDOEMyOjkxMjRBOjNDNDdDQTc6NEYyMEZGRjo2OTZCQTdCMyIsInZpc2l0b3JfaWQiOiI4MTY1Njg0MDk4MDAxMjUwMjI3IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 4c76bd395af1137127b6331b1a7dfc198d607981c3d2a0ca19f17af8ff1f8912 |
| hovercard-subject-tag | issue:2542902464 |
| github-keyboard-shortcuts | repository,issues,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/_view_fragments/issues/show/python/cpython/124342/issue_layout |
| twitter:image | https://opengraph.githubassets.com/fc9195d6ba58e618afd93f0ce255f09cf7052f37680076d00b2999bfa45f22c3/python/cpython/issues/124342 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/fc9195d6ba58e618afd93f0ce255f09cf7052f37680076d00b2999bfa45f22c3/python/cpython/issues/124342 |
| og:image:alt | The current implementation of PEP-649 and PEP-749 on main simply copies functions' __annotate__ in functools.update_wrapper (and thence functools.wraps): >>> def f(x: y): pass ... >>> from functool... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | JelleZijlstra |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f99f7c1d70f01da5b93e5ca90303359738944d8ab470e396496262c66e60b8d |
| turbo-cache-control | no-preview |
| 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 |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 82560a55c6b2054555076f46e683151ee28a19bc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width