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 <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