Title: Discussion: Runtime error when overriding a mutable key with a `ReadOnly` one · Issue #681 · python/typing_extensions · GitHub
Open Graph Title: Discussion: Runtime error when overriding a mutable key with a `ReadOnly` one · Issue #681 · python/typing_extensions
X Title: Discussion: Runtime error when overriding a mutable key with a `ReadOnly` one · Issue #681 · python/typing_extensions
Description: Follow up from here: #606 (comment) Background: Currently CPython emits a TypeError when a mutable key from a base TypedDict is overwritten by a ReadOnly one of a child: https://github.com/python/cpython/blob/805e3368d6d07e58430654d13652...
Open Graph Description: Follow up from here: #606 (comment) Background: Currently CPython emits a TypeError when a mutable key from a base TypedDict is overwritten by a ReadOnly one of a child: https://github.com/python/c...
X Description: Follow up from here: #606 (comment) Background: Currently CPython emits a TypeError when a mutable key from a base TypedDict is overwritten by a ReadOnly one of a child: https://github.com/python/c...
Opengraph URL: https://github.com/python/typing_extensions/issues/681
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Discussion: Runtime error when overriding a mutable key with a `ReadOnly` one","articleBody":"Follow up from here: https://github.com/python/typing_extensions/issues/606#issuecomment-3277382801\n\n\nBackground:\nCurrently CPython emits a TypeError when a mutable key from a base TypedDict is overwritten by a ReadOnly one of a child: https://github.com/python/cpython/blob/805e3368d6d07e58430654d1365283924fdf4143/Lib/typing.py#L3151\n\nand it has an explicit test for that behavior: https://github.com/python/cpython/blob/805e3368d6d07e58430654d1365283924fdf4143/Lib/test/test_typing.py#L9077\n\nHowever typing_extensions permits and tests for that:\n- https://github.com/python/typing_extensions/blob/main/src/typing_extensions.py#L1221\n- https://github.com/python/typing_extensions/blob/main/src/test_typing_extensions.py#L5000\n\nOriginally typing_extensions had the same behaviour as CPython, however that was changed: https://github.com/python/typing_extensions/commit/d6c50f585c386490d38ad6b8ce5543aed6e633a2\n\n\nThis adjustment was not taken into account when the CPython implementation was done: https://github.com/python/cpython/pull/116350\n\nAlthough this point was later raised in the issue (after the merge of the PR): https://github.com/python/cpython/issues/116127#issuecomment-3176307396\n\n\nMy opinion:\nFrom what i understand the TypeError in CPython for this behaviour is pretty unique, as i dont think any other such attribute is runtime enforced.\n\ntyping.Final and typing.ReadOnly even specify \"There is no runtime checking for this property.\" in the [docs](https://docs.python.org/3/library/typing.html#typing.Final). (Although that obviously refers them only being read, but still).\n\nAdditionally the typing docs in general state \"The Python runtime does not enforce function and variable type annotations. They can be used by third party tools such as [type checkers](https://docs.python.org/3/glossary.html#term-static-type-checker), IDEs, linters, etc.\". Lastly, neither the docs nor the PEP say anything about such a type error existing.\n\nSo i definitely feel like the optimal thing here would be to not have a runtime error.\n\nOn top of that i feel like removing a TypeError is probably a less intrusive change than adding one, even though changes in CPython are obviously more impactful than ones in typing_extensions.","author":{"url":"https://github.com/JanEricNitschke","@type":"Person","name":"JanEricNitschke"},"datePublished":"2025-09-13T09:24:45.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/681/typing_extensions/issues/681"}
| 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:6047f00a-756e-d2cb-f59e-1fc1da67643d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E7E0:10FD0C:A7F60B:E0521C:6969806D |
| html-safe-nonce | c88bdc53927d00ff65eb83d4f37e7f04b72ab137ee8b5b3cc8014b6610a2cadb |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFN0UwOjEwRkQwQzpBN0Y2MEI6RTA1MjFDOjY5Njk4MDZEIiwidmlzaXRvcl9pZCI6IjU1NzAwODY1MTAzNDY3MzE2MjkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 0e5d726abcf454db788f45cdc97602c3ab1b5986d616216ecbb0af97d9277ad8 |
| hovercard-subject-tag | issue:3412981416 |
| 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/typing_extensions/681/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3b04f3f3e3f8a64c2778c8aeb0c6c16b8f170be11852554b77fdfd3680a6f0a1/python/typing_extensions/issues/681 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3b04f3f3e3f8a64c2778c8aeb0c6c16b8f170be11852554b77fdfd3680a6f0a1/python/typing_extensions/issues/681 |
| og:image:alt | Follow up from here: #606 (comment) Background: Currently CPython emits a TypeError when a mutable key from a base TypedDict is overwritten by a ReadOnly one of a child: https://github.com/python/c... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | JanEricNitschke |
| hostname | github.com |
| expected-hostname | github.com |
| None | f33e4b94c8824ab2b434d82a94139432fb5ebee9df4b75304140ad22508c4a77 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/typing_extensions git https://github.com/python/typing_extensions.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 494077289 |
| octolytics-dimension-repository_nwo | python/typing_extensions |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 494077289 |
| octolytics-dimension-repository_network_root_nwo | python/typing_extensions |
| 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 | 48f380098b30acbb700b04f1724481ca10d574fc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width