Author: Armin Rigo <ar...@tunes.org> Branch: py3.5 Changeset: r88754:49831b800735 Date: 2016-11-29 17:53 +0100 http://bitbucket.org/pypy/pypy/changeset/49831b800735/
Log: merge heads diff --git a/pypy/interpreter/module.py b/pypy/interpreter/module.py --- a/pypy/interpreter/module.py +++ b/pypy/interpreter/module.py @@ -121,31 +121,8 @@ return space.newtuple(tup_return) def descr_module__repr__(self, space): - w_loader = space.finditem(self.w_dict, space.wrap('__loader__')) - if w_loader is not None: - try: - return space.call_method(w_loader, "module_repr", self) - except OperationError: - pass - try: - w_name = space.getattr(self, space.wrap('__name__')) - name = space.unicode_w(space.repr(w_name)) - except OperationError: - name = u"'?'" - - try: - w___file__ = space.getattr(self, space.wrap('__file__')) - except OperationError: - w___file__ = space.w_None - if not space.isinstance_w(w___file__, space.w_unicode): - if w_loader is not None: - w_loader_repr = space.unicode_w(space.repr(w_loader)) - return space.wrap(u"<module %s (%s)>" % (name, w_loader_repr)) - else: - return space.wrap(u"<module %s>" % (name,)) - else: - __file__ = space.unicode_w(space.repr(w___file__)) - return space.wrap(u"<module %s from %s>" % (name, __file__)) + w_importlib = space.getbuiltinmodule('_frozen_importlib') + return space.call_method(w_importlib, "_module_repr", self) def descr_getattribute(self, space, w_attr): from pypy.objspace.descroperation import object_getattribute diff --git a/pypy/interpreter/test/test_module.py b/pypy/interpreter/test/test_module.py --- a/pypy/interpreter/test/test_module.py +++ b/pypy/interpreter/test/test_module.py @@ -129,6 +129,20 @@ expected_repr = "<module 'test_module' ({})>".format(loader_repr) assert mod_repr == expected_repr + def test_repr_with_loader_with_raising_module_repr2(self): + import sys + test_module = type(sys)("test_module", "doc") + # If an exception occurs in module_repr(), the exception is caught + # and discarded, and the calculation of the module’s repr continues + # as if module_repr() did not exist. + class CustomLoaderWithRaisingRepr: + @classmethod + def module_repr(cls, module): + raise KeyboardInterrupt + + test_module.__loader__ = CustomLoaderWithRaisingRepr + raises(KeyboardInterrupt, 'repr(test_module)') + def test_repr_with_raising_loader_and___file__(self): import sys test_module = type(sys)("test_module", "doc") _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit