diff --git a/Doc/c-api/import.rst b/Doc/c-api/import.rst index 7aacc219a2bd619..f35786ff3f7061e 100644 --- a/Doc/c-api/import.rst +++ b/Doc/c-api/import.rst @@ -103,8 +103,8 @@ Importing Modules Return the module object corresponding to a module name. The *name* argument may be of the form ``package.module``. First check the - modules dictionary if there's one there, and if not, create a new one and - insert it in the modules dictionary. + :data:`sys.modules` dictionary if there's one there, and if not, create a + new one and insert it in the :data:`sys.modules` dictionary. Return a :term:`strong reference` to the module on success. Return ``NULL`` with an exception set on failure. diff --git a/Python/import.c b/Python/import.c index 969902afea1cd6b..f3174e9f12f3487 100644 --- a/Python/import.c +++ b/Python/import.c @@ -372,16 +372,7 @@ PyImport_AddModuleObject(PyObject *name) if (!mod) { return NULL; } - - // gh-86160: PyImport_AddModuleObject() returns a borrowed reference - PyObject *ref = PyWeakref_NewRef(mod, NULL); - Py_DECREF(mod); - if (ref == NULL) { - return NULL; - } - - mod = PyWeakref_GetObject(ref); - Py_DECREF(ref); + Py_DECREF(mod); // sys.modules holds a strong reference return mod; /* borrowed reference */ }