Skip to content

Commit a0fc619

Browse files
committed
Fix format specifiers in error messages for consistency and correctness
1 parent 1fd66ea commit a0fc619

25 files changed

+52
-53
lines changed

Modules/_asynciomodule.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2244,7 +2244,7 @@ enter_task(_PyThreadStateImpl *ts, PyObject *loop, PyObject *task)
22442244
PyExc_RuntimeError,
22452245
"Cannot enter into task %R while another " \
22462246
"task %R is being executed.",
2247-
task, ts->asyncio_running_task, NULL);
2247+
task, ts->asyncio_running_task);
22482248
return -1;
22492249
}
22502250

@@ -2265,7 +2265,7 @@ leave_task(_PyThreadStateImpl *ts, PyObject *loop, PyObject *task)
22652265
PyExc_RuntimeError,
22662266
"Invalid attempt to leave task %R while " \
22672267
"task %R is entered.",
2268-
task, ts->asyncio_running_task ? ts->asyncio_running_task : Py_None, NULL);
2268+
task, ts->asyncio_running_task ? ts->asyncio_running_task : Py_None);
22692269
return -1;
22702270
}
22712271
Py_CLEAR(ts->asyncio_running_task);
@@ -2328,7 +2328,7 @@ _asyncio_Task___init___impl(TaskObj *self, PyObject *coro, PyObject *loop,
23282328
self->task_log_destroy_pending = 0;
23292329
PyErr_Format(PyExc_TypeError,
23302330
"a coroutine was expected, got %R",
2331-
coro, NULL);
2331+
coro);
23322332
return -1;
23332333
}
23342334

Modules/_remote_debugging/asyncio.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ parse_task_name(
212212
set_exception_cause(unwinder, PyExc_RuntimeError, "Task name PyLong parsing failed");
213213
return NULL;
214214
}
215-
return PyUnicode_FromFormat("Task-%d", res);
215+
return PyUnicode_FromFormat("Task-%ld", res);
216216
}
217217

218218
if(!(GET_MEMBER(unsigned long, type_obj, unwinder->debug_offsets.type_object.tp_flags) & Py_TPFLAGS_UNICODE_SUBCLASS)) {

Modules/_ssl.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ fill_and_set_sslerror(_sslmodulestate *state,
592592
}
593593
else {
594594
if (PyUnicodeWriter_Format(
595-
writer, "unknown error (0x%x)", errcode) < 0) {
595+
writer, "unknown error (0x%lx)", errcode) < 0) {
596596
goto fail;
597597
}
598598
}
@@ -4059,7 +4059,7 @@ set_min_max_proto_version(PySSLContext *self, PyObject *arg, int what)
40594059
break;
40604060
default:
40614061
PyErr_Format(PyExc_ValueError,
4062-
"Unsupported TLS/SSL version 0x%x", v);
4062+
"Unsupported TLS/SSL version 0x%lx", v);
40634063
return -1;
40644064
}
40654065

@@ -4093,7 +4093,7 @@ set_min_max_proto_version(PySSLContext *self, PyObject *arg, int what)
40934093
}
40944094
if (result == 0) {
40954095
PyErr_Format(PyExc_ValueError,
4096-
"Unsupported protocol version 0x%x", v);
4096+
"Unsupported protocol version 0x%lx", v);
40974097
return -1;
40984098
}
40994099
return 0;

Modules/_testcapi/watchers.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ add_code_watcher(PyObject *self, PyObject *which_watcher)
364364
watcher_id = PyCode_AddWatcher(error_code_event_handler);
365365
}
366366
else {
367-
PyErr_Format(PyExc_ValueError, "invalid watcher %d", which_l);
367+
PyErr_Format(PyExc_ValueError, "invalid watcher %ld", which_l);
368368
return NULL;
369369
}
370370
if (watcher_id < 0) {
@@ -673,7 +673,7 @@ add_context_watcher(PyObject *self, PyObject *which_watcher)
673673
assert(PyLong_Check(which_watcher));
674674
long which_l = PyLong_AsLong(which_watcher);
675675
if (which_l < 0 || which_l >= (long)Py_ARRAY_LENGTH(callbacks)) {
676-
PyErr_Format(PyExc_ValueError, "invalid watcher %d", which_l);
676+
PyErr_Format(PyExc_ValueError, "invalid watcher %ld", which_l);
677677
return NULL;
678678
}
679679
int watcher_id = PyContext_AddWatcher(callbacks[which_l]);

Modules/_testcapimodule.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ test_sizeof_c_types(PyObject *self, PyObject *Py_UNUSED(ignored))
116116
do { \
117117
if (EXPECTED != sizeof(TYPE)) { \
118118
PyErr_Format(get_testerror(self), \
119-
"sizeof(%s) = %u instead of %u", \
120-
#TYPE, sizeof(TYPE), EXPECTED); \
119+
"sizeof(%s) = %zu instead of %u", \
120+
#TYPE, sizeof(TYPE), (unsigned)(EXPECTED)); \
121121
return (PyObject*)NULL; \
122122
} \
123123
} while (0)

Modules/_testinternalcapi.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -417,14 +417,14 @@ test_bswap(PyObject *self, PyObject *Py_UNUSED(args))
417417
uint16_t u16 = _Py_bswap16(UINT16_C(0x3412));
418418
if (u16 != UINT16_C(0x1234)) {
419419
PyErr_Format(PyExc_AssertionError,
420-
"_Py_bswap16(0x3412) returns %u", u16);
420+
"_Py_bswap16(0x3412) returns %d", u16);
421421
return NULL;
422422
}
423423

424424
uint32_t u32 = _Py_bswap32(UINT32_C(0x78563412));
425425
if (u32 != UINT32_C(0x12345678)) {
426426
PyErr_Format(PyExc_AssertionError,
427-
"_Py_bswap32(0x78563412) returns %lu", u32);
427+
"_Py_bswap32(0x78563412) returns %u", u32);
428428
return NULL;
429429
}
430430

@@ -711,7 +711,7 @@ check_bytes_find(const char *haystack0, const char *needle0,
711711
needle0, len_needle, offset);
712712
if (result_1 != expected) {
713713
PyErr_Format(PyExc_AssertionError,
714-
"Incorrect result_1: '%s' in '%s' (offset=%zd)",
714+
"Incorrect result_1: '%s' in '%s' (offset=%d)",
715715
needle0, haystack0, offset);
716716
return -1;
717717
}
@@ -735,7 +735,7 @@ check_bytes_find(const char *haystack0, const char *needle0,
735735
PyMem_Free(needle);
736736
if (result_2 != expected) {
737737
PyErr_Format(PyExc_AssertionError,
738-
"Incorrect result_2: '%s' in '%s' (offset=%zd)",
738+
"Incorrect result_2: '%s' in '%s' (offset=%d)",
739739
needle0, haystack0, offset);
740740
return -1;
741741
}
@@ -1158,7 +1158,7 @@ get_interp_settings(PyObject *self, PyObject *args)
11581158
}
11591159
else {
11601160
PyErr_Format(PyExc_NotImplementedError,
1161-
"%zd", interpid);
1161+
"%d", interpid);
11621162
return NULL;
11631163
}
11641164
assert(interp != NULL);

Modules/_zoneinfo.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,7 @@ load_data(zoneinfo_state *state, PyZoneInfo_ZoneInfo *self, PyObject *file_obj)
991991
}
992992

993993
if (!PyTuple_CheckExact(data_tuple)) {
994-
PyErr_Format(PyExc_TypeError, "Invalid data result type: %r",
994+
PyErr_Format(PyExc_TypeError, "Invalid data result type: %R",
995995
data_tuple);
996996
goto error;
997997
}

Modules/_zstd/compressor.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ zstd_contentsize_converter(PyObject *size, unsigned long long *p)
7474
if (PyErr_ExceptionMatches(PyExc_OverflowError)) {
7575
PyErr_Format(PyExc_ValueError,
7676
"size argument should be a positive int less "
77-
"than %ull", ZSTD_CONTENTSIZE_ERROR);
77+
"than %llu", ZSTD_CONTENTSIZE_ERROR);
7878
return 0;
7979
}
8080
return 0;
@@ -83,7 +83,7 @@ zstd_contentsize_converter(PyObject *size, unsigned long long *p)
8383
*p = ZSTD_CONTENTSIZE_ERROR;
8484
PyErr_Format(PyExc_ValueError,
8585
"size argument should be a positive int less "
86-
"than %ull", ZSTD_CONTENTSIZE_ERROR);
86+
"than %llu", ZSTD_CONTENTSIZE_ERROR);
8787
return 0;
8888
}
8989
*p = pledged_size;

Modules/binascii.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,7 @@ binascii_a2b_base85_impl(PyObject *module, Py_buffer *data,
13501350
state = get_binascii_state(module);
13511351
if (state != NULL) {
13521352
PyErr_Format(state->Error,
1353-
"Base85 overflow in hunk starting at byte %d",
1353+
"Base85 overflow in hunk starting at byte %zd",
13541354
(data->len - ascii_len) / 5 * 5);
13551355
}
13561356
goto error;
@@ -1361,7 +1361,7 @@ binascii_a2b_base85_impl(PyObject *module, Py_buffer *data,
13611361
else {
13621362
state = get_binascii_state(module);
13631363
if (state != NULL) {
1364-
PyErr_Format(state->Error, "bad Base85 character at position %d",
1364+
PyErr_Format(state->Error, "bad Base85 character at position %zd",
13651365
data->len - ascii_len);
13661366
}
13671367
goto error;

Modules/socketmodule.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3357,8 +3357,7 @@ sock_setsockopt(PyObject *self, PyObject *args)
33573357
arglen = PyTuple_Size(args);
33583358
if (arglen == 3 && optval == Py_None) {
33593359
PyErr_Format(PyExc_TypeError,
3360-
"setsockopt() requires 4 arguments when the third argument is None",
3361-
arglen);
3360+
"setsockopt() requires 4 arguments when the third argument is None");
33623361
return NULL;
33633362
}
33643363
if (arglen == 4 && optval != Py_None) {

0 commit comments

Comments
 (0)