Eric Snow added the comment: > I'm sorry, but this seems like it should be an importlib internal > affair. The new exception is too much in everyone's face, because > the exception name gets printed on every traceback.
That's the crux of the issue. If there isn't much utility outside importlib to distinguishing between module-not-found and other causes of ImportError, then there isn't much point to a new exception. It just boils down to what the other potential causes of ImportError are and how much people care about them. I keep thinking about PEP 3151 (IOError/OSError hierarchy rework) and the lessons we've learned about exception attributes vs. subclasses. For readability and write-ability, I'd rather write this: try: from _collections import OrderedDict except ModuleNotFoundError: pass than this: try: from _collections import OrderedDict except ImportError as e: if e.reason is not importlib.machinery.ImportReason.MODULE_NOT_FOUND: raise But the relevant question is, what is the benefit (outside importlib) of either over this: try: from _collections import OrderedDict except ImportError: pass ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue15767> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com