Title: [1.19 regression] copy.replace doesn't work with NamedTuple anymore · Issue #21528 · python/mypy · GitHub
Open Graph Title: [1.19 regression] copy.replace doesn't work with NamedTuple anymore · Issue #21528 · python/mypy
X Title: [1.19 regression] copy.replace doesn't work with NamedTuple anymore · Issue #21528 · python/mypy
Description: Bug Report Using copy.replace on a NamedTuple produces an object that is not considered assignable to the NamedTuple type by mypy 1.19.0 and newer. To Reproduce from copy import replace from typing import NamedTuple class NT(NamedTuple):...
Open Graph Description: Bug Report Using copy.replace on a NamedTuple produces an object that is not considered assignable to the NamedTuple type by mypy 1.19.0 and newer. To Reproduce from copy import replace from typing...
X Description: Bug Report Using copy.replace on a NamedTuple produces an object that is not considered assignable to the NamedTuple type by mypy 1.19.0 and newer. To Reproduce from copy import replace from typing...
Opengraph URL: https://github.com/python/mypy/issues/21528
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[1.19 regression] copy.replace doesn't work with NamedTuple anymore","articleBody":"**Bug Report**\n\nUsing [`copy.replace`](https://docs.python.org/3/library/copy.html#copy.replace) on a [`NamedTuple`](https://docs.python.org/3/library/typing.html#typing.NamedTuple) produces an object that is not considered assignable to the NamedTuple type by mypy 1.19.0 and newer.\n\n**To Reproduce**\n\n```python\nfrom copy import replace\nfrom typing import NamedTuple\n\nclass NT(NamedTuple):\n foo: int\n\ndef mre(nt: NT) -> NT:\n return replace(nt, foo=3)\n```\n\n\n\n**Expected Behavior**\n\n* 1.18.2 ([playground](https://mypy-play.net/?mypy=1.18.2&python=3.14&gist=6a2a0703452aab7090f4954a661fcf70)) : success\n\n**Actual Behavior**\n\n\n* 1.19.0 ([playground](https://mypy-play.net/?mypy=1.19.0&python=3.14&gist=6a2a0703452aab7090f4954a661fcf70)) : `main.py:10: error: Incompatible return value type (got \"NT\", expected \"NT\") [return-value]`\n\nSome `reveal_type`s ([playground](https://mypy-play.net/?mypy=1.19.0&python=3.14&gist=10f10a3a149b773ca5716d3fcb7e957e)):\n```python\ndef mre(nt: NT) -> NT:\n reveal_type(nt)\n replaced = replace(nt, foo=3)\n reveal_type(replaced)\n return replaced\n```\ngive\n```\nmain.py:10: note: Revealed type is \"tuple[builtins.int, fallback=__main__.NT]\"\nmain.py:12: note: Revealed type is \"__main__.NT\"\nmain.py:13: error: Incompatible return value type (got \"NT\", expected \"NT\") [return-value]\n```\n\n**Your Environment**\n\n- Reproduced from 1.19.0 to master. I'll try to bisect it to the exact commit.\n- Python version used: 3.14\n\n","author":{"url":"https://github.com/loic-simon","@type":"Person","name":"loic-simon"},"datePublished":"2026-05-21T10:07:03Z","url":"https://github.com/python/mypy/issues/21528"}
| 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:5c7f279b-b3c2-3bcf-fc87-ad4b66ba8cad |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C312:B7CF9:4918F9:61FFAB:6B002CFA |
| html-safe-nonce | f9e9e6c802ae4f17f74883fbb9b6a9e27cb6283c10d3577559b4cdc345c81d7b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMzEyOkI3Q0Y5OjQ5MThGOTo2MUZGQUI6NkIwMDJDRkEiLCJ2aXNpdG9yX2lkIjoiMjU4OTU2NDE5NTQ4NTc4OTQzNCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 490bc5b6f9525ca2dc327a685a89776abaa5c204b7ef4afd9a138360257338f1 |
| hovercard-subject-tag | issue:4493626148 |
| 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/21528/issue_layout |
| twitter:image | https://opengraph.githubassets.com/6f4b2450e67f2b5e80bbb7d74d241184f85d289024f21c2980db2f2ecc1976bf/python/mypy/issues/21528 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/6f4b2450e67f2b5e80bbb7d74d241184f85d289024f21c2980db2f2ecc1976bf/python/mypy/issues/21528 |
| og:image:alt | Bug Report Using copy.replace on a NamedTuple produces an object that is not considered assignable to the NamedTuple type by mypy 1.19.0 and newer. To Reproduce from copy import replace from typing... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | loic-simon |
| 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