Skip to content

No explicit way to create a TypeAliasType instance with a __module__ of choice #151607

Closed as duplicate

Description

@flying-sheep

The __module__ attribute is readonly, and will always be derived using caller():

PyObject *module = caller();
if (module == NULL) {
return NULL;
}

So the only ways to create a type alias with a __module__ of choice is by managing globals()["__name__"] using e.g. eval(..., globals=...), temporarily setting globals()["name"] = ..., or defining a custom module with that __name__.

It would make more sense to just make __module__ mutable.

Activity

  1. picnixz commented on Jun 17, 2026

    @picnixz
    Member

    Isn't it a duplicate of an exisint issue already?

  2. added
    type-featureA feature request or enhancement
    interpreter-core(Objects, Python, Grammar, and Parser dirs)
    pendingThe issue will be closed if no feedback is provided
    on Jun 17, 2026
  3. picnixz commented on Jun 17, 2026

    @picnixz
    Member

    It is a dup of #149171 was changed in 3.15+.

  4. flying-sheep commented on Jun 18, 2026

    @flying-sheep
    ContributorAuthor

    Oops sorry!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    interpreter-core(Objects, Python, Grammar, and Parser dirs)pendingThe issue will be closed if no feedback is providedtopic-typingtype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions