[issue15767] add ImportNotFoundError
Eric Snow
report at bugs.python.org
Wed Feb 20 01:25:08 CET 2013
Eric Snow added the comment:
The common case for catching ImportError is exactly what ModuleNotFoundError represents. If people are already going to change their code to handle just this special case, I'd think having the subclass would be the better route. I find it simpler (both to update existing code and to read:
try:
from _thread import _local as local
except ModuleNotFoundError:
from _threading_local import local
vs.
try:
from _thread import _local as local
except ImportError as e:
if e.not_found:
from _threading_local import local
else:
raise
And for the broader case:
try:
import breakfast
except ModuleNotFoundError:
class breakfast:
spam = 0
eggs = 1
ham = 2
except ImportError as e:
log_some_message("uh oh: {}".format(e))
raise
vs.
try:
import breakfast
except ImportError as e:
if e.not_found:
class breakfast:
spam = 0
eggs = 1
ham = 2
else:
log_some_message("uh oh: {}".format(e))
raise
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue15767>
_______________________________________
More information about the Python-bugs-list
mailing list