You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Make TypeAliasType __module__ attribute writable #149171
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__ from a frame walk. 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.
There is currently no way to fix this after the fact, because __module__ is read-only:
Meanwhile 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.
Has this already been discussed elsewhere?
I have already discussed this feature proposal on Discourse
Activity
pythongh-149171: Make TypeAliasType __module__ writable
pythongh-149171: Make TypeAliasType __module__ writable
pythongh-149171: Make TypeAliasType __module__ writable
pythongh-149171: Make TypeAliasType __module__ writable
pythongh-149171: Make TypeAliasType __module__ writable
pythongh-149171: Make TypeAliasType __module__ writable
gh-149171: Make TypeAliasType __module__ writable (#149172)
TypeAliasTypeinstance with a__module__of choice #151607 as a duplicate of this issue