From 9fd3d2db00c9bc731db71cdb6d3f091c6c93b326 Mon Sep 17 00:00:00 2001 From: Ben Hsing Date: Mon, 24 Jun 2024 03:47:44 +0000 Subject: [PATCH] gh-120713: use "%04ld" instead of "%04d" to avoid unnecessary int conversion --- Modules/_datetimemodule.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index a57b45c404bd5f..ca6be7a3838a16 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -1942,13 +1942,10 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple, #ifdef NORMALIZE_CENTURY else if (ch == 'Y') { /* 0-pad year with century on platforms that do not do so */ - PyObject *year = PyObject_GetAttrString(object, "year"); - if (year == NULL) - goto Done; char formatted[5]; - ntoappend = sprintf(formatted, "%04d", (int)PyLong_AsLong(year)); + ntoappend = sprintf(formatted, "%04ld", + PyLong_AsLong(PyTuple_GET_ITEM(timetuple, 0))); ptoappend = formatted; - Py_DECREF(year); } #endif else {