Skip to content

Commit 524103a

Browse files
Address review comments.
1 parent 3ec086f commit 524103a

File tree

3 files changed

+8
-10
lines changed

3 files changed

+8
-10
lines changed

Include/internal/pycore_bytes_methods.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ extern PyObject *_Py_bytes_endswith(const char *str, Py_ssize_t len,
4848
extern PyObject* _Py_bytes_maketrans(Py_buffer *frm, Py_buffer *to);
4949

5050
/* Helper for repr(bytes) and repr(bytearray). */
51-
extern PyObject *_Py_bytes_repr(const char *, Py_ssize_t, int);
51+
extern PyObject *_Py_bytes_repr(const char *, Py_ssize_t, int, const char *);
5252

5353
/* Shared __doc__ strings. */
5454
extern const char _Py_isspace__doc__[];

Objects/bytearrayobject.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,12 +1073,9 @@ bytearray_repr_lock_held(PyObject *op)
10731073
_Py_CRITICAL_SECTION_ASSERT_OBJECT_LOCKED(op);
10741074
const char *className = _PyType_Name(Py_TYPE(op));
10751075
PyObject *bytes_repr = _Py_bytes_repr(PyByteArray_AS_STRING(op),
1076-
PyByteArray_GET_SIZE(op), 1);
1076+
PyByteArray_GET_SIZE(op), 1,
1077+
"bytearray");
10771078
if (bytes_repr == NULL) {
1078-
if (PyErr_ExceptionMatches(PyExc_OverflowError)) {
1079-
PyErr_SetString(PyExc_OverflowError,
1080-
"bytearray object is too large to make repr");
1081-
}
10821079
return NULL;
10831080
}
10841081
PyObject *res = PyUnicode_FromFormat("%s(%U)", className, bytes_repr);

Objects/bytesobject.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,11 +1340,12 @@ PyObject *
13401340
PyBytes_Repr(PyObject *obj, int smartquotes)
13411341
{
13421342
return _Py_bytes_repr(PyBytes_AS_STRING(obj),
1343-
PyBytes_GET_SIZE(obj), smartquotes);
1343+
PyBytes_GET_SIZE(obj), smartquotes, "bytes");
13441344
}
13451345

13461346
PyObject *
1347-
_Py_bytes_repr(const char *data, Py_ssize_t length, int smartquotes)
1347+
_Py_bytes_repr(const char *data, Py_ssize_t length, int smartquotes,
1348+
const char *classname)
13481349
{
13491350
Py_ssize_t i;
13501351
Py_ssize_t newsize, squotes, dquotes;
@@ -1411,8 +1412,8 @@ _Py_bytes_repr(const char *data, Py_ssize_t length, int smartquotes)
14111412
return v;
14121413

14131414
overflow:
1414-
PyErr_SetString(PyExc_OverflowError,
1415-
"bytes object is too large to make repr");
1415+
PyErr_Format(PyExc_OverflowError,
1416+
"%s object is too large to make repr", classname);
14161417
return NULL;
14171418
}
14181419

0 commit comments

Comments
 (0)