@@ -389,8 +389,17 @@ def synopsis(filename, cache={}):
389389class ErrorDuringImport (Exception ):
390390 """Errors that occurred while trying to import something to document it."""
391391 def __init__ (self , filename , exc_info ):
392+ if not isinstance (exc_info , tuple ):
393+ assert isinstance (exc_info , BaseException )
394+ self .exc = type (exc_info )
395+ self .value = exc_info
396+ self .tb = exc_info .__traceback__
397+ else :
398+ warnings .warn ("A tuple value for exc_info is deprecated, use an exception instance" ,
399+ DeprecationWarning )
400+
401+ self .exc , self .value , self .tb = exc_info
392402 self .filename = filename
393- self .exc , self .value , self .tb = exc_info
394403
395404 def __str__ (self ):
396405 exc = self .exc .__name__
@@ -411,8 +420,8 @@ def importfile(path):
411420 spec = importlib .util .spec_from_file_location (name , path , loader = loader )
412421 try :
413422 return importlib ._bootstrap ._load (spec )
414- except :
415- raise ErrorDuringImport (path , sys . exc_info () )
423+ except BaseException as err :
424+ raise ErrorDuringImport (path , err )
416425
417426def safeimport (path , forceload = 0 , cache = {}):
418427 """Import a module; handle errors; return None if the module isn't found.
@@ -440,21 +449,20 @@ def safeimport(path, forceload=0, cache={}):
440449 cache [key ] = sys .modules [key ]
441450 del sys .modules [key ]
442451 module = __import__ (path )
443- except :
452+ except BaseException as err :
444453 # Did the error occur before or after the module was found?
445- (exc , value , tb ) = info = sys .exc_info ()
446454 if path in sys .modules :
447455 # An error occurred while executing the imported module.
448- raise ErrorDuringImport (sys .modules [path ].__file__ , info )
449- elif exc is SyntaxError :
456+ raise ErrorDuringImport (sys .modules [path ].__file__ , err )
457+ elif type ( err ) is SyntaxError :
450458 # A SyntaxError occurred before we could execute the module.
451- raise ErrorDuringImport (value .filename , info )
452- elif issubclass ( exc , ImportError ) and value .name == path :
459+ raise ErrorDuringImport (err .filename , err )
460+ elif isinstance ( err , ImportError ) and err .name == path :
453461 # No such module in the path.
454462 return None
455463 else :
456464 # Some other error occurred during the importing process.
457- raise ErrorDuringImport (path , sys . exc_info () )
465+ raise ErrorDuringImport (path , err )
458466 for part in path .split ('.' )[1 :]:
459467 try : module = getattr (module , part )
460468 except AttributeError : return None
@@ -1997,8 +2005,8 @@ def __call__(self, request=_GoInteractive):
19972005 if request is not self ._GoInteractive :
19982006 try :
19992007 self .help (request )
2000- except ImportError as e :
2001- self .output .write (f'{ e } \n ' )
2008+ except ImportError as err :
2009+ self .output .write (f'{ err } \n ' )
20022010 else :
20032011 self .intro ()
20042012 self .interact ()
@@ -2405,8 +2413,8 @@ def run(self):
24052413 docsvr = DocServer (self .host , self .port , self .ready )
24062414 self .docserver = docsvr
24072415 docsvr .serve_until_quit ()
2408- except Exception as e :
2409- self .error = e
2416+ except Exception as err :
2417+ self .error = err
24102418
24112419 def ready (self , server ):
24122420 self .serving = True
0 commit comments