diff --git a/Doc/c-api/import.rst b/Doc/c-api/import.rst index 1174f69a60e..96b74140218 100644 --- a/Doc/c-api/import.rst +++ b/Doc/c-api/import.rst @@ -349,7 +349,8 @@ Importing Modules .. c:function:: PyObject* PyImport_GetLazyImportsFilter() - Gets the current lazy imports filter. Returns a :term:`strong reference`. + Return a :term:`strong reference` to the current lazy imports filter, + or ``NULL`` if none exists. This function always succeeds. .. versionadded:: next diff --git a/Python/import.c b/Python/import.c index 64d797e888f..60eacffd036 100644 --- a/Python/import.c +++ b/Python/import.c @@ -4802,7 +4802,9 @@ PyImport_SetLazyImportsFilter(PyObject *filter) return 0; } -/* Gets the lazy imports filter. Returns a new reference. */ +/* Return a strong reference to the current lazy imports filter + * or NULL if none exists. This function always succeeds. + */ PyObject * PyImport_GetLazyImportsFilter(void) { diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 1634a6df4d1..9cbcaafab98 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -2815,6 +2815,7 @@ sys_get_lazy_imports_filter_impl(PyObject *module) { PyObject *filter = PyImport_GetLazyImportsFilter(); if (filter == NULL) { + assert(!PyErr_Occurred()); Py_RETURN_NONE; } return filter;