Author: Mariano Anaya <marianoan...@gmail.com> Branch: py3.6 Changeset: r91877:5a01e5b5546a Date: 2017-07-15 15:18 +0200 http://bitbucket.org/pypy/pypy/changeset/5a01e5b5546a/
Log: Add ModuleNotFoundError New exception added in Python 3.6. It's a subclass of ImportError. h ttps://docs.python.org/3/library/exceptions.html#ModuleNotFoundError diff --git a/pypy/module/exceptions/__init__.py b/pypy/module/exceptions/__init__.py --- a/pypy/module/exceptions/__init__.py +++ b/pypy/module/exceptions/__init__.py @@ -4,7 +4,7 @@ class Module(MixedModule): applevel_name = '__exceptions__' appleveldefs = {} - + interpleveldefs = { 'ArithmeticError' : 'interp_exceptions.W_ArithmeticError', 'AssertionError' : 'interp_exceptions.W_AssertionError', @@ -39,6 +39,7 @@ 'KeyboardInterrupt' : 'interp_exceptions.W_KeyboardInterrupt', 'LookupError' : 'interp_exceptions.W_LookupError', 'MemoryError' : 'interp_exceptions.W_MemoryError', + 'ModuleNotFoundError': 'interp_exceptions.W_ModuleNotFoundError', 'NameError' : 'interp_exceptions.W_NameError', 'NotADirectoryError': 'interp_exceptions.W_NotADirectoryError', 'NotImplementedError' : 'interp_exceptions.W_NotImplementedError', diff --git a/pypy/module/exceptions/interp_exceptions.py b/pypy/module/exceptions/interp_exceptions.py --- a/pypy/module/exceptions/interp_exceptions.py +++ b/pypy/module/exceptions/interp_exceptions.py @@ -345,6 +345,10 @@ W_UnicodeError = _new_exception('UnicodeError', W_ValueError, """Unicode related error.""") +W_ModuleNotFoundError = _new_exception( + 'ModuleNotFoundError', W_ImportError, """Module not found.""" +) + class W_UnicodeTranslateError(W_UnicodeError): """Unicode translation error.""" diff --git a/pypy/module/exceptions/test/test_exc.py b/pypy/module/exceptions/test/test_exc.py --- a/pypy/module/exceptions/test/test_exc.py +++ b/pypy/module/exceptions/test/test_exc.py @@ -296,6 +296,14 @@ assert ImportError("message", path="y").path == "y" raises(TypeError, ImportError, invalid="z") + def test_modulenotfounderror(self): + assert ModuleNotFoundError("message").name is None + assert ModuleNotFoundError("message").path is None + assert ModuleNotFoundError("message", name="x").name == "x" + assert ModuleNotFoundError("message", path="y").path == "y" + raises(TypeError, ModuleNotFoundError, invalid="z") + assert repr(ModuleNotFoundError('test')) == "ModuleNotFoundError('test',)" + def test_blockingioerror(self): args = ("a", "b", "c", "d", "e") for n in range(6): _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit