Skip to content

gh-149171: Make TypeAliasType __module__ writable#149172

Open
ericmarkmartin wants to merge 2 commits intopython:mainfrom
ericmarkmartin:typealiastype-writable-module
Open

gh-149171: Make TypeAliasType __module__ writable#149172
ericmarkmartin wants to merge 2 commits intopython:mainfrom
ericmarkmartin:typealiastype-writable-module

Conversation

@ericmarkmartin
Copy link
Copy Markdown

@ericmarkmartin ericmarkmartin commented Apr 30, 2026

Copy link
Copy Markdown
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should update the TypeAlias docs (both rST and the one at L2193).

Comment thread Objects/typevarobject.c Outdated
Comment on lines +2005 to +2007
PyObject *old_module = ta->module;
Py_XDECREF(old_module);
ta->module = Py_XNewRef(value);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use Py_XSETREF instead. More generally, making it writable looks like we may introduce races on the free-threaded build so I think the getter/setter will need a critical section. I however don't know whether this should be considered an atomic change or not.

@read-the-docs-community
Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #32490942 | 📁 Comparing c506040 against main (5110738)

  🔍 Preview build  

14 files changed · ± 14 modified

± Modified

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make TypeAliasType __module__ attribute writable

2 participants