Skip to content

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

@flying-sheep

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.

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
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions