@@ -389,8 +389,17 @@ def synopsis(filename, cache={}):
389
389
class ErrorDuringImport (Exception ):
390
390
"""Errors that occurred while trying to import something to document it."""
391
391
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
392
402
self .filename = filename
393
- self .exc , self .value , self .tb = exc_info
394
403
395
404
def __str__ (self ):
396
405
exc = self .exc .__name__
@@ -411,8 +420,8 @@ def importfile(path):
411
420
spec = importlib .util .spec_from_file_location (name , path , loader = loader )
412
421
try :
413
422
return importlib ._bootstrap ._load (spec )
414
- except :
415
- raise ErrorDuringImport (path , sys . exc_info () )
423
+ except BaseException as err :
424
+ raise ErrorDuringImport (path , err )
416
425
417
426
def safeimport (path , forceload = 0 , cache = {}):
418
427
"""Import a module; handle errors; return None if the module isn't found.
@@ -440,21 +449,20 @@ def safeimport(path, forceload=0, cache={}):
440
449
cache [key ] = sys .modules [key ]
441
450
del sys .modules [key ]
442
451
module = __import__ (path )
443
- except :
452
+ except BaseException as err :
444
453
# Did the error occur before or after the module was found?
445
- (exc , value , tb ) = info = sys .exc_info ()
446
454
if path in sys .modules :
447
455
# 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 :
450
458
# 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 :
453
461
# No such module in the path.
454
462
return None
455
463
else :
456
464
# Some other error occurred during the importing process.
457
- raise ErrorDuringImport (path , sys . exc_info () )
465
+ raise ErrorDuringImport (path , err )
458
466
for part in path .split ('.' )[1 :]:
459
467
try : module = getattr (module , part )
460
468
except AttributeError : return None
@@ -1997,8 +2005,8 @@ def __call__(self, request=_GoInteractive):
1997
2005
if request is not self ._GoInteractive :
1998
2006
try :
1999
2007
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 ' )
2002
2010
else :
2003
2011
self .intro ()
2004
2012
self .interact ()
@@ -2405,8 +2413,8 @@ def run(self):
2405
2413
docsvr = DocServer (self .host , self .port , self .ready )
2406
2414
self .docserver = docsvr
2407
2415
docsvr .serve_until_quit ()
2408
- except Exception as e :
2409
- self .error = e
2416
+ except Exception as err :
2417
+ self .error = err
2410
2418
2411
2419
def ready (self , server ):
2412
2420
self .serving = True
0 commit comments