mirror of
https://github.com/python/cpython.git
synced 2025-09-15 05:06:12 +00:00
Fix issue 5230 by having pydoc's safeimport check to see if the import
error was thrown from itself in order to decide if the module can't be found. Thanks to Lucas Prado Melo for collaborating on the fix and tests.
This commit is contained in:
parent
3a1dbb05a1
commit
ef087da9e7
4 changed files with 51 additions and 3 deletions
|
@ -55,6 +55,7 @@ Richard Chamberlain, for the first implementation of textdoc.
|
|||
import sys, imp, os, re, types, inspect, __builtin__, pkgutil
|
||||
from repr import Repr
|
||||
from string import expandtabs, find, join, lower, split, strip, rfind, rstrip
|
||||
from traceback import extract_tb
|
||||
try:
|
||||
from collections import deque
|
||||
except ImportError:
|
||||
|
@ -299,9 +300,9 @@ def safeimport(path, forceload=0, cache={}):
|
|||
elif exc is SyntaxError:
|
||||
# A SyntaxError occurred before we could execute the module.
|
||||
raise ErrorDuringImport(value.filename, info)
|
||||
elif exc is ImportError and \
|
||||
split(lower(str(value)))[:2] == ['no', 'module']:
|
||||
# The module was not found.
|
||||
elif exc is ImportError and extract_tb(tb)[-1][2]=='safeimport':
|
||||
# The import error occurred directly in this function,
|
||||
# which means there is no such module in the path.
|
||||
return None
|
||||
else:
|
||||
# Some other error occurred during the importing process.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue