Bug report
PyImport_GetImporter() can return NULL with set or not set error. The latter happens only if sys.path_hooks or sys.path_importer_cache was deleted, or in more obscure cases: when string allocation for strings "path_hooks" or "path_importer_cache" fail, or the sys module was not yet created. These cases so obscure, that the user code most likely do not expect this. The only place where PyImport_GetImporter() is used in Python itself expects an error to be set if NULL is returned.
PyImport_GetImporter() can crash (in debug build) or raise SystemError if sys.path_hooks is not a list or sys.path_importer_cache is not a dict. Note that both are set to None in _PyImport_FiniExternal() (which is called in Py_FinalizeEx() and Py_EndInterpreter()).
Crash is unacceptable, so asserts should be replaced with runtime checks and raising an exception (RuntimeError looks suitable).
And I think that PyImport_GetImporter() should set RuntimeError when it fails to get sys.path_hooks or sys.path_importer_cache. It is the most common error in similar cases.
Linked PRs
Bug report
PyImport_GetImporter()can return NULL with set or not set error. The latter happens only ifsys.path_hooksorsys.path_importer_cachewas deleted, or in more obscure cases: when string allocation for strings "path_hooks" or "path_importer_cache" fail, or thesysmodule was not yet created. These cases so obscure, that the user code most likely do not expect this. The only place wherePyImport_GetImporter()is used in Python itself expects an error to be set if NULL is returned.PyImport_GetImporter()can crash (in debug build) or raise SystemError ifsys.path_hooksis not a list orsys.path_importer_cacheis not a dict. Note that both are set to None in_PyImport_FiniExternal()(which is called inPy_FinalizeEx()andPy_EndInterpreter()).Crash is unacceptable, so asserts should be replaced with runtime checks and raising an exception (RuntimeError looks suitable).
And I think that
PyImport_GetImporter()should set RuntimeError when it fails to getsys.path_hooksorsys.path_importer_cache. It is the most common error in similar cases.Linked PRs