Title: `namedtuple.__replace__` should return `Self` · Issue #17497 · python/mypy · GitHub
Open Graph Title: `namedtuple.__replace__` should return `Self` · Issue #17497 · python/mypy
X Title: `namedtuple.__replace__` should return `Self` · Issue #17497 · python/mypy
Description: __replace__ was added onto NamedTuple as a part of 3.13 related changes, however, instead of returning None, it should return Self. Looking in cpython we can see this is the case. Furthermore, this is important for compatibility with cop...
Open Graph Description: __replace__ was added onto NamedTuple as a part of 3.13 related changes, however, instead of returning None, it should return Self. Looking in cpython we can see this is the case. Furthermore, this...
X Description: __replace__ was added onto NamedTuple as a part of 3.13 related changes, however, instead of returning None, it should return Self. Looking in cpython we can see this is the case. Furthermore, this...
Opengraph URL: https://github.com/python/mypy/issues/17497
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`namedtuple.__replace__` should return `Self`","articleBody":"`__replace__` was added onto `NamedTuple` [as a part of 3.13 related changes](https://github.com/python/mypy/pull/17259), however, instead of returning `None`, it should return `Self`. [Looking in cpython we can see this is the case](https://github.com/python/cpython/blob/53e12025cd7d7ee46ce10cc8f1b722c55716b892/Lib/collections/__init__.py#L498).\r\n\r\nFurthermore, this is important for compatibility with `copy.replace`. In https://github.com/python/typeshed/pull/12262 we're adding a protocol that requires replaceable objects implement:\r\n\r\n```python\r\nclass _SupportsReplace(Protocol):\r\n def __replace__(self, *args: Any, **kwargs: Any) -> Self: ...\r\n```\r\n\r\nWith `namedtuple.__replace__` returning `None`, users will return into false positives here, when in reality it should work just fine.\r\n","author":{"url":"https://github.com/max-muoto","@type":"Person","name":"max-muoto"},"datePublished":"2024-07-06T19:50:18Z","url":"https://github.com/python/mypy/issues/17497"}
| 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:906f2b06-5278-9c05-cedd-63ba27f0bb94 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BB1C:302FC:618CEF:8254A6:6B003423 |
| html-safe-nonce | 571e2e1e90e2bc4da761286923abb3bf3c0418486f478ec711d401d3a2f69b1f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQjFDOjMwMkZDOjYxOENFRjo4MjU0QTY6NkIwMDM0MjMiLCJ2aXNpdG9yX2lkIjoiNTYxNzgwMTU2NTUxMjQxNDI0MyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 4d4c21cf2d3a0b9db7bece97fbc3369c73a7316eb9db65e74436b2c01576fb98 |
| hovercard-subject-tag | issue:2393695537 |
| 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/mypy/17497/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b4134506fbe875c2067b3ea595f1c22253d050f3fbec12279d073e8e69e590dc/python/mypy/issues/17497 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b4134506fbe875c2067b3ea595f1c22253d050f3fbec12279d073e8e69e590dc/python/mypy/issues/17497 |
| og:image:alt | __replace__ was added onto NamedTuple as a part of 3.13 related changes, however, instead of returning None, it should return Self. Looking in cpython we can see this is the case. Furthermore, this... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | max-muoto |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/mypy git https://github.com/python/mypy.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 7053637 |
| octolytics-dimension-repository_nwo | python/mypy |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 7053637 |
| octolytics-dimension-repository_network_root_nwo | python/mypy |
| 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 | f3f3a43ca095cdea3abbb394112e971f9fdb94fa |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width