https://github.com/python/cpython/commit/499df18d805ca81025e6f8ba0a2bde727a918322
commit: 499df18d805ca81025e6f8ba0a2bde727a918322
branch: 3.13
author: Serhiy Storchaka <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2026-03-31T08:44:51Z
summary:

[3.13] gh-146615: Fix format specifiers in Objects/ directory (GH-146620) 
(GH-146655)

(cherry picked from commit bbf7fb2c15a1dc9a54d10937c3d0831b0968257d)

Co-authored-by: sunmy2019 <[email protected]>

files:
M Objects/descrobject.c
M Objects/enumobject.c
M Objects/exceptions.c
M Objects/funcobject.c
M Objects/memoryobject.c
M Objects/typeobject.c
M Objects/typevarobject.c
M Objects/unicodeobject.c

diff --git a/Objects/descrobject.c b/Objects/descrobject.c
index d33152bb85489e..a0d9220259cb80 100644
--- a/Objects/descrobject.c
+++ b/Objects/descrobject.c
@@ -1606,7 +1606,7 @@ property_set_name(PyObject *self, PyObject *args) {
     if (PyTuple_GET_SIZE(args) != 2) {
         PyErr_Format(
                 PyExc_TypeError,
-                "__set_name__() takes 2 positional arguments but %d were 
given",
+                "__set_name__() takes 2 positional arguments but %zd were 
given",
                 PyTuple_GET_SIZE(args));
         return NULL;
     }
diff --git a/Objects/enumobject.c b/Objects/enumobject.c
index 556666779d8522..bffe7172a393d7 100644
--- a/Objects/enumobject.c
+++ b/Objects/enumobject.c
@@ -145,7 +145,7 @@ enumerate_vectorcall(PyObject *type, PyObject *const *args,
     }
 
     PyErr_Format(PyExc_TypeError,
-        "enumerate() takes at most 2 arguments (%d given)", nargs + nkwargs);
+        "enumerate() takes at most 2 arguments (%zd given)", nargs + nkwargs);
     return NULL;
 }
 
diff --git a/Objects/exceptions.c b/Objects/exceptions.c
index 6c1807715c0f14..1eb2a3bbe24571 100644
--- a/Objects/exceptions.c
+++ b/Objects/exceptions.c
@@ -759,7 +759,7 @@ BaseExceptionGroup_new(PyTypeObject *type, PyObject *args, 
PyObject *kwds)
         if (!PyExceptionInstance_Check(exc)) {
             PyErr_Format(
                 PyExc_ValueError,
-                "Item %d of second argument (exceptions) is not an exception",
+                "Item %zd of second argument (exceptions) is not an exception",
                 i);
             goto error;
         }
@@ -1512,7 +1512,7 @@ PyUnstable_Exc_PrepReraiseStar(PyObject *orig, PyObject 
*excs)
         PyObject *exc = PyList_GET_ITEM(excs, i);
         if (exc == NULL || !(PyExceptionInstance_Check(exc) || 
Py_IsNone(exc))) {
             PyErr_Format(PyExc_TypeError,
-                         "item %d of excs is not an exception", i);
+                         "item %zd of excs is not an exception", i);
             return NULL;
         }
     }
diff --git a/Objects/funcobject.c b/Objects/funcobject.c
index 61140fd4f1859e..a39b5464f4d4ac 100644
--- a/Objects/funcobject.c
+++ b/Objects/funcobject.c
@@ -629,7 +629,7 @@ func_set_code(PyObject *self, PyObject *value, void 
*Py_UNUSED(ignored))
     if (nclosure != nfree) {
         PyErr_Format(PyExc_ValueError,
                      "%U() requires a code object with %zd free vars,"
-                     " not %zd",
+                     " not %d",
                      op->func_name,
                      nclosure, nfree);
         return -1;
@@ -964,7 +964,7 @@ func_new_impl(PyTypeObject *type, PyCodeObject *code, 
PyObject *globals,
     nclosure = closure == Py_None ? 0 : PyTuple_GET_SIZE(closure);
     if (code->co_nfreevars != nclosure)
         return PyErr_Format(PyExc_ValueError,
-                            "%U requires closure of length %zd, not %zd",
+                            "%U requires closure of length %d, not %zd",
                             code->co_name, code->co_nfreevars, nclosure);
     if (nclosure) {
         Py_ssize_t i;
diff --git a/Objects/memoryobject.c b/Objects/memoryobject.c
index 8dc53c9ccbbacb..535e0b3c1dc027 100644
--- a/Objects/memoryobject.c
+++ b/Objects/memoryobject.c
@@ -2413,7 +2413,7 @@ ptr_from_tuple(const Py_buffer *view, PyObject *tup)
 
     if (nindices > view->ndim) {
         PyErr_Format(PyExc_TypeError,
-                     "cannot index %zd-dimension view with %zd-element tuple",
+                     "cannot index %d-dimension view with %zd-element tuple",
                      view->ndim, nindices);
         return NULL;
     }
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 0c16377034fbb7..51d1ce573d12e1 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -4414,28 +4414,28 @@ check_basicsize_includes_size_and_offsets(PyTypeObject* 
type)
 
     if (type->tp_base && type->tp_base->tp_basicsize > type->tp_basicsize) {
         PyErr_Format(PyExc_TypeError,
-                     "tp_basicsize for type '%s' (%d) is too small for base 
'%s' (%d)",
+                     "tp_basicsize for type '%s' (%zd) is too small for base 
'%s' (%zd)",
                      type->tp_name, type->tp_basicsize,
                      type->tp_base->tp_name, type->tp_base->tp_basicsize);
         return 0;
     }
     if (type->tp_weaklistoffset + (Py_ssize_t)sizeof(PyObject*) > max) {
         PyErr_Format(PyExc_TypeError,
-                     "weaklist offset %d is out of bounds for type '%s' 
(tp_basicsize = %d)",
+                     "weaklist offset %zd is out of bounds for type '%s' 
(tp_basicsize = %zd)",
                      type->tp_weaklistoffset,
                      type->tp_name, type->tp_basicsize);
         return 0;
     }
     if (type->tp_dictoffset + (Py_ssize_t)sizeof(PyObject*) > max) {
         PyErr_Format(PyExc_TypeError,
-                     "dict offset %d is out of bounds for type '%s' 
(tp_basicsize = %d)",
+                     "dict offset %zd is out of bounds for type '%s' 
(tp_basicsize = %zd)",
                      type->tp_dictoffset,
                      type->tp_name, type->tp_basicsize);
         return 0;
     }
     if (type->tp_vectorcall_offset + (Py_ssize_t)sizeof(vectorcallfunc*) > 
max) {
         PyErr_Format(PyExc_TypeError,
-                     "vectorcall offset %d is out of bounds for type '%s' 
(tp_basicsize = %d)",
+                     "vectorcall offset %zd is out of bounds for type '%s' 
(tp_basicsize = %zd)",
                      type->tp_vectorcall_offset,
                      type->tp_name, type->tp_basicsize);
         return 0;
diff --git a/Objects/typevarobject.c b/Objects/typevarobject.c
index 1398f911e54ef5..5caec8a73bbddf 100644
--- a/Objects/typevarobject.c
+++ b/Objects/typevarobject.c
@@ -557,7 +557,7 @@ typevar_typing_prepare_subst_impl(typevarobject *self, 
PyObject *alias,
     }
     Py_DECREF(params);
     PyErr_Format(PyExc_TypeError,
-                 "Too few arguments for %S; actual %d, expected at least %d",
+                 "Too few arguments for %S; actual %zd, expected at least %zd",
                  alias, args_len, i + 1);
     return NULL;
 }
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 395430e398d50d..696bb100c6bf55 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -8127,7 +8127,7 @@ charmap_decode_mapping(const char *s,
                 goto Undefined;
             if (value < 0 || value > MAX_UNICODE) {
                 PyErr_Format(PyExc_TypeError,
-                             "character mapping must be in range(0x%x)",
+                             "character mapping must be in range(0x%lx)",
                              (unsigned long)MAX_UNICODE + 1);
                 goto onError;
             }
@@ -8861,8 +8861,8 @@ charmaptranslate_lookup(Py_UCS4 c, PyObject *mapping, 
PyObject **result)
         long value = PyLong_AS_LONG(x);
         if (value < 0 || value > MAX_UNICODE) {
             PyErr_Format(PyExc_ValueError,
-                         "character mapping must be in range(0x%x)",
-                         MAX_UNICODE+1);
+                         "character mapping must be in range(0x%lx)",
+                         (unsigned long)MAX_UNICODE + 1);
             Py_DECREF(x);
             return -1;
         }

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to