Skip to content

Commit aa75f6a

Browse files
committed
use PyUnicdodeWriter_Format and if statement braces
1 parent 6e416c6 commit aa75f6a

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

Objects/exceptions.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1871,24 +1871,32 @@ ImportError_repr(PyObject *self)
18711871
PyObject *r = BaseException_repr(self);
18721872
PyImportErrorObject *exc = PyImportErrorObject_CAST(self);
18731873
PyUnicodeWriter *writer = PyUnicodeWriter_Create(0);
1874-
if (writer == NULL) goto error;
1875-
if (PyUnicodeWriter_WriteSubstring(writer, r, 0, PyUnicode_GET_LENGTH(r)-1) < 0) goto error;
1874+
if (writer == NULL) {
1875+
goto error;
1876+
}
1877+
if (PyUnicodeWriter_WriteSubstring(writer, r, 0, PyUnicode_GET_LENGTH(r)-1) < 0) {
1878+
goto error;
1879+
}
18761880
if (exc->name) {
18771881
if (hasargs) {
1878-
if (PyUnicodeWriter_WriteASCII(writer, ", ", 2) < 0) goto error;
1882+
if (PyUnicodeWriter_WriteASCII(writer, ", ", 2) < 0) {
1883+
goto error;
1884+
}
1885+
}
1886+
if (PyUnicodeWriter_Format(writer, "name=%R", exc->name) < 0) {
1887+
goto error;
18791888
}
1880-
if (PyUnicodeWriter_WriteASCII(writer, "name='", 6) < 0) goto error;
1881-
if (PyUnicodeWriter_WriteSubstring(writer, exc->name, 0, PyUnicode_GET_LENGTH(exc->name)) < 0) goto error;
1882-
if (PyUnicodeWriter_WriteASCII(writer, "'", 1) < 0) goto error;
18831889
hasargs = 1;
18841890
}
18851891
if (exc->path) {
18861892
if (hasargs) {
1887-
if (PyUnicodeWriter_WriteASCII(writer, ", ", 2) < 0) goto error;
1893+
if (PyUnicodeWriter_WriteASCII(writer, ", ", 2) < 0) {
1894+
goto error;
1895+
}
1896+
}
1897+
if (PyUnicodeWriter_Format(writer, "path=%R", exc->path) < 0) {
1898+
goto error;
18881899
}
1889-
if (PyUnicodeWriter_WriteASCII(writer, "path='", 6) < 0) goto error;
1890-
if (PyUnicodeWriter_WriteSubstring(writer, exc->path, 0, PyUnicode_GET_LENGTH(exc->path)) < 0) goto error;
1891-
if (PyUnicodeWriter_WriteASCII(writer, "'", 1) < 0) goto error;
18921900
}
18931901
if (PyUnicodeWriter_WriteASCII(writer, ")", 1) < 0) goto error;
18941902
return PyUnicodeWriter_Finish(writer);

0 commit comments

Comments
 (0)