Title: Add generalized replace() function · Issue #108751 · python/cpython · GitHub
Open Graph Title: Add generalized replace() function · Issue #108751 · python/cpython
X Title: Add generalized replace() function · Issue #108751 · python/cpython
Description: Feature or enhancement Has this already been discussed elsewhere? I have already discussed this feature proposal on Discourse Links to previous discussion of this feature: https://discuss.python.org/t/generalize-replace-function/28511 Pr...
Open Graph Description: Feature or enhancement Has this already been discussed elsewhere? I have already discussed this feature proposal on Discourse Links to previous discussion of this feature: https://discuss.python.or...
X Description: Feature or enhancement Has this already been discussed elsewhere? I have already discussed this feature proposal on Discourse Links to previous discussion of this feature: https://discuss.python.or...
Opengraph URL: https://github.com/python/cpython/issues/108751
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Add generalized replace() function","articleBody":"# Feature or enhancement\n\n### Has this already been discussed elsewhere?\n\nI have already discussed this feature proposal on Discourse\n\n### Links to previous discussion of this feature:\n\nhttps://discuss.python.org/t/generalize-replace-function/28511\n\n### Proposal:\n\nSome classes have the `replace()` method, which creates a modified copy of the object (modified values are provided as keyword arguments). Named tuples have the `_replace()` for this (to avoid conflict with attribute `replace`). Dataclasses provide a global function for this.\n\nI proposed to generalize `dataclasses.replace()` to support all classes which need this feature. By the result of the discussion on discuss.python.org, the new function will be added in the `copy` module as `copy.replace()`. `dataclasses.replace()` will continue to support only dataclasses. Dataclasses, named tuples and all classes which currently have the `replace()` method with suitable semantic will get also the `__replace__()` method. Now you can add such feature in new classes without conflicting with the `replace` attribute, and use this feature in general code without conflicting with `str.replace()` and like.\n\nFor now, `copy.replace()` is more limited than `copy.copy()` and does not fall back to use the powerful pickle protocol.\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-108752\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/serhiy-storchaka","@type":"Person","name":"serhiy-storchaka"},"datePublished":"2023-09-01T10:10:40Z","url":"https://github.com/python/cpython/issues/108751"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:52597d32-0843-b559-3d5c-5e75da2031bb |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C038:157BA1:BE28E7:FF5F92:6B004F7F |
| html-safe-nonce | 6e1b5d99d0405c6bdf1061aebb615f5e3ffcc0342747f25c6b5505f45ca0cfcb |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMDM4OjE1N0JBMTpCRTI4RTc6RkY1RjkyOjZCMDA0RjdGIiwidmlzaXRvcl9pZCI6IjYwMTc4NzMwOTE5MTU0MzU5MDMiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 7ad223351dc938ec67ee415bb5393e88414abe5145432e99435390a01ad9c703 |
| hovercard-subject-tag | issue:1877143329 |
| 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/108751/issue_layout |
| twitter:image | https://opengraph.githubassets.com/dd203c66603bb202808d52c4227b91b202638d6133dd6fc1459b9779bd50d629/python/cpython/issues/108751 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/dd203c66603bb202808d52c4227b91b202638d6133dd6fc1459b9779bd50d629/python/cpython/issues/108751 |
| og:image:alt | Feature or enhancement Has this already been discussed elsewhere? I have already discussed this feature proposal on Discourse Links to previous discussion of this feature: https://discuss.python.or... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | serhiy-storchaka |
| hostname | github.com |
| expected-hostname | github.com |
| None | f420f4996e6b1ff1ccd6d7683f8134f4b5f0f8a50124c210dbfe7490e5644abb |
| 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 | 26e00df917aba0f128135dc073ea0c5e33a70d40 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width