[pypy-commit] pypy py3.7-bpo-30399: Implement bpo-30399: Get rid of trailing comma in the repr of BaseException

Yannick_Jadoul pypy.commits at gmail.com
Sun Dec 29 15:26:12 EST 2019


Author: Yannick Jadoul <yannick.jadoul at belgacom.net>
Branch: py3.7-bpo-30399
Changeset: r98405:705f6a3a7d9a
Date: 2019-12-29 21:25 +0100
http://bitbucket.org/pypy/pypy/changeset/705f6a3a7d9a/

Log:	Implement bpo-30399: Get rid of trailing comma in the repr of
	BaseException

diff --git a/lib-python/3/test/test_gdb.py b/lib-python/3/test/test_gdb.py
--- a/lib-python/3/test/test_gdb.py
+++ b/lib-python/3/test/test_gdb.py
@@ -436,7 +436,7 @@
     id(e)
 ''')
         self.assertEqual(gdb_repr,
-                         "RuntimeError('I am an error',)")
+                         "RuntimeError('I am an error')")
 
 
         # Test division by zero:
@@ -447,7 +447,7 @@
     id(e)
 ''')
         self.assertEqual(gdb_repr,
-                         "ZeroDivisionError('division by zero',)")
+                         "ZeroDivisionError('division by zero')")
 
     def test_modern_class(self):
         'Verify the pretty-printing of new-style class instances'
diff --git a/pypy/interpreter/test/test_error.py b/pypy/interpreter/test/test_error.py
--- a/pypy/interpreter/test/test_error.py
+++ b/pypy/interpreter/test/test_error.py
@@ -42,7 +42,7 @@
     val = operr.get_w_value(space)
     assert space.isinstance_w(val, space.w_AttributeError)
     w_repr = space.repr(val)
-    assert space.text_w(w_repr) == "AttributeError(\"no attribute 'foo'\",)"
+    assert space.text_w(w_repr) == "AttributeError(\"no attribute 'foo'\")"
 
 def test_oefmt_T(space):
     operr = oefmt(space.w_AttributeError,
@@ -110,7 +110,7 @@
     operr = OperationError(space.w_ValueError, space.wrap("message"))
     assert operr.errorstr(space) == "ValueError: message"
     assert operr.errorstr(space, use_repr=True) == (
-        "ValueError: ValueError('message',)")
+        "ValueError: ValueError('message')")
     operr = OperationError(space.w_ValueError, space.w_None)
     assert operr.errorstr(space) == "ValueError"
     operr = OperationError(space.w_ValueError,
diff --git a/pypy/module/cpyext/test/test_cpyext.py b/pypy/module/cpyext/test/test_cpyext.py
--- a/pypy/module/cpyext/test/test_cpyext.py
+++ b/pypy/module/cpyext/test/test_cpyext.py
@@ -751,7 +751,7 @@
         module = self.import_module(name='foo', body=body)
 
         # uncaught interplevel exceptions are turned into SystemError
-        expected = "ZeroDivisionError('integer division or modulo by zero',)"
+        expected = "ZeroDivisionError('integer division or modulo by zero')"
         exc = raises(SystemError, module.crash1)
         assert exc.value.args[0] == expected
 
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
@@ -149,11 +149,16 @@
             return space.call_function(space.w_unicode, w_tup)
 
     def descr_repr(self, space):
-        if self.args_w:
+        lgt = len(self.args_w)
+        if lgt == 0:
+            args_repr = b"()"
+        elif lgt == 1:
+            args_repr = (b"(" +
+                space.utf8_w(space.repr(self.args_w[0])) +
+                b")")
+        else:
             args_repr = space.utf8_w(
                 space.repr(space.newtuple(self.args_w)))
-        else:
-            args_repr = b"()"
         clsname = self.getclass(space).getname(space)
         return space.newtext(clsname + args_repr)
 
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
@@ -10,7 +10,7 @@
         assert repr(BaseException()) == 'BaseException()'
         raises(AttributeError, getattr, BaseException(), 'message')
         raises(AttributeError, getattr, BaseException(3), 'message')
-        assert repr(BaseException(3)) == 'BaseException(3,)'
+        assert repr(BaseException(3)) == 'BaseException(3)'
         assert str(BaseException(3)) == '3'
         assert BaseException().args == ()
         assert BaseException(3).args == (3,)
@@ -328,7 +328,7 @@
         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',)"
+        assert repr(ModuleNotFoundError('test')) == "ModuleNotFoundError('test')"
 
     def test_blockingioerror(self):
         args = ("a", "b", "c", "d", "e")


More information about the pypy-commit mailing list