New submission from Joon-Kyu Park: `pydoc.safeimport()` should return `None` if the module isn't found.
If Python's default `__import__` is monkey patched, (e.g., by using gevent) the function misbehaves. According to the current implementation, the function returns `None` by checking the only last entry of the traceback if `ImportError` is thrown during calling `__import__()`. If `__import__` is monkey patched, extra entries can be mixed into the original traceback when `ImportError` is raised. In the case when the module is not found, `ErrorDuringImport` is being raised rather than returning `None` after failing checking the traceback because current implementation only checks the last traceback entry. The important thing is to check whether `ImportError` is raised inside `safeimport()`, I think it's okay to check the whole traceback entries instead of checking the only last item. Please check the attached patch which I suggest. Thank you. ---------- components: Library (Lib) files: pydoc.patch keywords: patch messages: 278726 nosy: Joon-Kyu Park priority: normal severity: normal status: open title: pydoc.safeimport() raises ErrorDuringImport() if __builtin__.__import__ is monkey patched type: behavior versions: Python 2.7 Added file: http://bugs.python.org/file45102/pydoc.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue28451> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com