Title: Make TypeAliasType __module__ attribute writable · Issue #149171 · python/cpython · GitHub
Open Graph Title: Make TypeAliasType __module__ attribute writable · Issue #149171 · python/cpython
X Title: Make TypeAliasType __module__ attribute writable · Issue #149171 · python/cpython
Description: Feature or enhancement Proposal: Make the __module__ attribute on TypeAliasType writable. This allows users to overwrite the attribute when frame introspection gets it wrong. Motivation typing.TypeAliasType currently derives __module__ f...
Open Graph Description: Feature or enhancement Proposal: Make the __module__ attribute on TypeAliasType writable. This allows users to overwrite the attribute when frame introspection gets it wrong. Motivation typing.Type...
X Description: Feature or enhancement Proposal: Make the __module__ attribute on TypeAliasType writable. This allows users to overwrite the attribute when frame introspection gets it wrong. Motivation typing.Type...
Opengraph URL: https://github.com/python/cpython/issues/149171
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Make TypeAliasType __module__ attribute writable","articleBody":"# Feature or enhancement\n\n### Proposal:\n\nMake the `__module__` attribute on `TypeAliasType` writable. This allows users to overwrite the attribute when frame introspection gets it wrong.\n\n### Motivation\n\n`typing.TypeAliasType` currently derives `__module__` from a [frame walk](https://github.com/python/cpython/blob/d71e3bc5a0f2f7af407eb32a8a5b36acf66070aa/Objects/typevarobject.c#L391). This is unsuitable when constructing TypeAliasType objects inside exec, from C, or with a factory helper. In such cases frame introspection returns None or the wrong module.\n\nThere is currently no way to fix this after the fact, because `__module__` is read-only:\n\n```py\n\u003e\u003e\u003e from typing import TypeAliasType\n\u003e\u003e\u003e ta = TypeAliasType(\"A\", int)\n\u003e\u003e\u003e ta.__module__ = \"x\"\nAttributeError: attribute '__module__' of 'typing.TypeAliasType' objects is not writable\n```\n\nMeanwhile there are consumers that rely on `__module__`, such as IDE go-to-definition or introspection-based stub generation (e.g. with `f\"{alias.__module__}.{alias.__name__}\"`). Such tools have no good recourse when `__module__` is wrong.\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/adding-a-module-keyword-argument-to-typing-typealiastype/107087\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-149172\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/ericmarkmartin","@type":"Person","name":"ericmarkmartin"},"datePublished":"2026-04-30T05:28:14.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/149171/cpython/issues/149171"}
| 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:58b03266-2561-781e-2641-b88c4eead22b |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A8E2:1EE1:208A70:2AA183:6A4EE194 |
| html-safe-nonce | ea5e2161d153a92d7c327d0aaaee3eb8ec004056bed57fdf8b537a9e63aaf419 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBOEUyOjFFRTE6MjA4QTcwOjJBQTE4Mzo2QTRFRTE5NCIsInZpc2l0b3JfaWQiOiI0NTQ3NDM5ODc2NDY3Nzc3OTQwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 73da973ddc6360a6c9e3d53d0c655774ec002ee7d789c5557ee3f042c13d22e8 |
| hovercard-subject-tag | issue:4355523753 |
| 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/149171/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4c9d73d87da278810c1f34ffa8f3c7cd45d540a26c29940a59054438b7e90dc4/python/cpython/issues/149171 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4c9d73d87da278810c1f34ffa8f3c7cd45d540a26c29940a59054438b7e90dc4/python/cpython/issues/149171 |
| og:image:alt | Feature or enhancement Proposal: Make the __module__ attribute on TypeAliasType writable. This allows users to overwrite the attribute when frame introspection gets it wrong. Motivation typing.Type... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | ericmarkmartin |
| hostname | github.com |
| expected-hostname | github.com |
| None | d12176b31601daf8d3de9a378cbbcf7dac6f33d990d1faedcb9c9b9ff3cbb1ed |
| 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 | 49a1d75361a644bf2b85ea827cc4d0c97ca18701 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width