summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2017-11-15 17:53:28 +0200
committerGitHub <noreply@github.com>2017-11-15 17:53:28 +0200
commitf8a4c03ede6048022f60a58d5a21b278b78a8a16 (patch)
treed9f7f1d0e827315be914b2408359067a12bcbaa2
parentaca7f574b06c72c85a5e3e4b16a8a5e384a7c4a8 (diff)
downloadcpython-git-f8a4c03ede6048022f60a58d5a21b278b78a8a16.tar.gz
bpo-30399: Get rid of trailing comma in the repr of BaseException. (#1650)
-rw-r--r--Lib/test/test_baseexception.py2
-rw-r--r--Lib/test/test_httplib.py2
-rw-r--r--Lib/test/test_yield_from.py18
-rw-r--r--Misc/NEWS.d/next/Core and Builtins/2017-10-12-22-21-01.bpo-30399.45f1gv.rst2
-rw-r--r--Objects/exceptions.c6
5 files changed, 18 insertions, 12 deletions
diff --git a/Lib/test/test_baseexception.py b/Lib/test/test_baseexception.py
index 27d514fe2e..c055ee3d83 100644
--- a/Lib/test/test_baseexception.py
+++ b/Lib/test/test_baseexception.py
@@ -92,7 +92,7 @@ class ExceptionClassTests(unittest.TestCase):
exc = Exception(arg)
results = ([len(exc.args), 1], [exc.args[0], arg],
[str(exc), str(arg)],
- [repr(exc), exc.__class__.__name__ + repr(exc.args)])
+ [repr(exc), '%s(%r)' % (exc.__class__.__name__, arg)])
self.interface_test_driver(results)
def test_interface_multi_arg(self):
diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py
index 0d79cae509..a3f8194dc4 100644
--- a/Lib/test/test_httplib.py
+++ b/Lib/test/test_httplib.py
@@ -497,7 +497,7 @@ class BasicTest(TestCase):
def test_bad_status_repr(self):
exc = client.BadStatusLine('')
- self.assertEqual(repr(exc), '''BadStatusLine("\'\'",)''')
+ self.assertEqual(repr(exc), '''BadStatusLine("''")''')
def test_partial_reads(self):
# if we have Content-Length, HTTPResponse knows when to close itself,
diff --git a/Lib/test/test_yield_from.py b/Lib/test/test_yield_from.py
index d1da838ac7..ce21c3df81 100644
--- a/Lib/test/test_yield_from.py
+++ b/Lib/test/test_yield_from.py
@@ -418,7 +418,7 @@ class TestPEP380Operation(unittest.TestCase):
"Yielded g2 spam",
"Yielded g2 more spam",
"Finishing g2",
- "g2 returned StopIteration(3,)",
+ "g2 returned StopIteration(3)",
"Yielded g1 eggs",
"Finishing g1",
])
@@ -696,15 +696,15 @@ class TestPEP380Operation(unittest.TestCase):
"g starting",
"f resuming g",
"g returning 1",
- "f caught StopIteration(1,)",
+ "f caught StopIteration(1)",
"g starting",
"f resuming g",
"g returning (2,)",
- "f caught StopIteration((2,),)",
+ "f caught StopIteration((2,))",
"g starting",
"f resuming g",
- "g returning StopIteration(3,)",
- "f caught StopIteration(StopIteration(3,),)",
+ "g returning StopIteration(3)",
+ "f caught StopIteration(StopIteration(3))",
])
def test_send_and_return_with_value(self):
@@ -741,17 +741,17 @@ class TestPEP380Operation(unittest.TestCase):
"f sending spam to g",
"g received 'spam'",
"g returning 1",
- 'f caught StopIteration(1,)',
+ 'f caught StopIteration(1)',
'g starting',
'f sending spam to g',
"g received 'spam'",
'g returning (2,)',
- 'f caught StopIteration((2,),)',
+ 'f caught StopIteration((2,))',
'g starting',
'f sending spam to g',
"g received 'spam'",
- 'g returning StopIteration(3,)',
- 'f caught StopIteration(StopIteration(3,),)'
+ 'g returning StopIteration(3)',
+ 'f caught StopIteration(StopIteration(3))'
])
def test_catching_exception_from_subgen_and_returning(self):
diff --git a/Misc/NEWS.d/next/Core and Builtins/2017-10-12-22-21-01.bpo-30399.45f1gv.rst b/Misc/NEWS.d/next/Core and Builtins/2017-10-12-22-21-01.bpo-30399.45f1gv.rst
new file mode 100644
index 0000000000..ccd1575ec9
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2017-10-12-22-21-01.bpo-30399.45f1gv.rst
@@ -0,0 +1,2 @@
+Standard repr() of BaseException with a single argument no longer contains
+redundant trailing comma.
diff --git a/Objects/exceptions.c b/Objects/exceptions.c
index 637d7660d3..4901eb1cc3 100644
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -117,7 +117,11 @@ static PyObject *
BaseException_repr(PyBaseExceptionObject *self)
{
const char *name = _PyType_Name(Py_TYPE(self));
- return PyUnicode_FromFormat("%s%R", name, self->args);
+ if (PyTuple_GET_SIZE(self->args) == 1)
+ return PyUnicode_FromFormat("%s(%R)", name,
+ PyTuple_GET_ITEM(self->args, 0));
+ else
+ return PyUnicode_FromFormat("%s%R", name, self->args);
}
/* Pickling support */