From ee232cade28512564da43ee58157dd7eb95dfce7 Mon Sep 17 00:00:00 2001 From: hauntsaninja <> Date: Mon, 18 May 2020 22:06:50 -0700 Subject: [PATCH 01/11] datetime.date.fromordinal --- Modules/_datetimemodule.c | 46 ++++++++++++++++-------------- Modules/clinic/_datetimemodule.c.h | 37 +++++++++++++++++++++++- 2 files changed, 60 insertions(+), 23 deletions(-) diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index 7a5efd23b9e45e..fba228dbfb6e2a 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -2940,27 +2940,33 @@ datetime_date_fromtimestamp_capi(PyObject *cls, PyObject *args) return result; } -/* Return new date from proleptic Gregorian ordinal. Raises ValueError if - * the ordinal is out of range. - */ + +/*[clinic input] +@classmethod +datetime.date.fromordinal + + ordinal: int + / + +int -> date corresponding to a proleptic Gregorian ordinal. + +Raises ValueError if the ordinal is out of range. +[clinic start generated code]*/ + static PyObject * -date_fromordinal(PyObject *cls, PyObject *args) +datetime_date_fromordinal_impl(PyTypeObject *type, int ordinal) +/*[clinic end generated code: output=ea5cc69d86614a6b input=1d7158c082e677fd]*/ { PyObject *result = NULL; - int ordinal; - - if (PyArg_ParseTuple(args, "i:fromordinal", &ordinal)) { - int year; - int month; - int day; + int year; + int month; + int day; - if (ordinal < 1) - PyErr_SetString(PyExc_ValueError, "ordinal must be " - ">= 1"); - else { - ord_to_ymd(ordinal, &year, &month, &day); - result = new_date_subclass_ex(year, month, day, cls); - } + if (ordinal < 1) + PyErr_SetString(PyExc_ValueError, "ordinal must be >= 1"); + else { + ord_to_ymd(ordinal, &year, &month, &day); + result = new_date_subclass_ex(year, month, day, (PyObject *) type); } return result; } @@ -3485,11 +3491,7 @@ static PyMethodDef date_methods[] = { /* Class methods: */ DATETIME_DATE_FROMTIMESTAMP_METHODDEF - - {"fromordinal", (PyCFunction)date_fromordinal, METH_VARARGS | - METH_CLASS, - PyDoc_STR("int -> date corresponding to a proleptic Gregorian " - "ordinal.")}, + DATETIME_DATE_FROMORDINAL_METHODDEF {"fromisoformat", (PyCFunction)date_fromisoformat, METH_O | METH_CLASS, diff --git a/Modules/clinic/_datetimemodule.c.h b/Modules/clinic/_datetimemodule.c.h index 973a4ea025347f..8ae1e5400a0077 100644 --- a/Modules/clinic/_datetimemodule.c.h +++ b/Modules/clinic/_datetimemodule.c.h @@ -14,6 +14,41 @@ PyDoc_STRVAR(datetime_date_fromtimestamp__doc__, #define DATETIME_DATE_FROMTIMESTAMP_METHODDEF \ {"fromtimestamp", (PyCFunction)datetime_date_fromtimestamp, METH_O|METH_CLASS, datetime_date_fromtimestamp__doc__}, +PyDoc_STRVAR(datetime_date_fromordinal__doc__, +"fromordinal($type, ordinal, /)\n" +"--\n" +"\n" +"int -> date corresponding to a proleptic Gregorian ordinal.\n" +"\n" +"Raises ValueError if the ordinal is out of range."); + +#define DATETIME_DATE_FROMORDINAL_METHODDEF \ + {"fromordinal", (PyCFunction)datetime_date_fromordinal, METH_O|METH_CLASS, datetime_date_fromordinal__doc__}, + +static PyObject * +datetime_date_fromordinal_impl(PyTypeObject *type, int ordinal); + +static PyObject * +datetime_date_fromordinal(PyTypeObject *type, PyObject *arg) +{ + PyObject *return_value = NULL; + int ordinal; + + if (PyFloat_Check(arg)) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + ordinal = _PyLong_AsInt(arg); + if (ordinal == -1 && PyErr_Occurred()) { + goto exit; + } + return_value = datetime_date_fromordinal_impl(type, ordinal); + +exit: + return return_value; +} + static PyObject * iso_calendar_date_new_impl(PyTypeObject *type, int year, int week, int weekday); @@ -109,4 +144,4 @@ datetime_datetime_now(PyTypeObject *type, PyObject *const *args, Py_ssize_t narg exit: return return_value; } -/*[clinic end generated code: output=5e17549f29a439a5 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=a78f8891b2c32698 input=a9049054013a1b77]*/ From 78e71d012d241a5503604b2ea50ca7d7e3599638 Mon Sep 17 00:00:00 2001 From: hauntsaninja <> Date: Mon, 18 May 2020 22:19:00 -0700 Subject: [PATCH 02/11] datetime.date.fromisoformat --- Modules/_datetimemodule.c | 29 ++++++++++++++++++----------- Modules/clinic/_datetimemodule.c.h | 11 ++++++++++- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index fba228dbfb6e2a..69ba4f033857e9 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -2971,13 +2971,23 @@ datetime_date_fromordinal_impl(PyTypeObject *type, int ordinal) return result; } -/* Return the new date from a string as generated by date.isoformat() */ +/*[clinic input] +@classmethod +datetime.date.fromisoformat + + date_string: object + / + +str -> Construct a date from the output of date.isoformat() +[clinic start generated code]*/ + static PyObject * -date_fromisoformat(PyObject *cls, PyObject *dtstr) +datetime_date_fromisoformat(PyTypeObject *type, PyObject *date_string) +/*[clinic end generated code: output=6657c70f3442350a input=cecf94602c2e7fd8]*/ { - assert(dtstr != NULL); + assert(date_string != NULL); - if (!PyUnicode_Check(dtstr)) { + if (!PyUnicode_Check(date_string)) { PyErr_SetString(PyExc_TypeError, "fromisoformat: argument must be str"); return NULL; @@ -2985,7 +2995,7 @@ date_fromisoformat(PyObject *cls, PyObject *dtstr) Py_ssize_t len; - const char *dt_ptr = PyUnicode_AsUTF8AndSize(dtstr, &len); + const char *dt_ptr = PyUnicode_AsUTF8AndSize(date_string, &len); if (dt_ptr == NULL) { goto invalid_string_error; } @@ -3004,10 +3014,10 @@ date_fromisoformat(PyObject *cls, PyObject *dtstr) goto invalid_string_error; } - return new_date_subclass_ex(year, month, day, cls); + return new_date_subclass_ex(year, month, day, (PyObject *) type); invalid_string_error: - PyErr_Format(PyExc_ValueError, "Invalid isoformat string: %R", dtstr); + PyErr_Format(PyExc_ValueError, "Invalid isoformat string: %R", date_string); return NULL; } @@ -3492,10 +3502,7 @@ static PyMethodDef date_methods[] = { /* Class methods: */ DATETIME_DATE_FROMTIMESTAMP_METHODDEF DATETIME_DATE_FROMORDINAL_METHODDEF - - {"fromisoformat", (PyCFunction)date_fromisoformat, METH_O | - METH_CLASS, - PyDoc_STR("str -> Construct a date from the output of date.isoformat()")}, + DATETIME_DATE_FROMISOFORMAT_METHODDEF {"fromisocalendar", (PyCFunction)(void(*)(void))date_fromisocalendar, METH_VARARGS | METH_KEYWORDS | METH_CLASS, diff --git a/Modules/clinic/_datetimemodule.c.h b/Modules/clinic/_datetimemodule.c.h index 8ae1e5400a0077..f5133e35747b01 100644 --- a/Modules/clinic/_datetimemodule.c.h +++ b/Modules/clinic/_datetimemodule.c.h @@ -49,6 +49,15 @@ datetime_date_fromordinal(PyTypeObject *type, PyObject *arg) return return_value; } +PyDoc_STRVAR(datetime_date_fromisoformat__doc__, +"fromisoformat($type, date_string, /)\n" +"--\n" +"\n" +"str -> Construct a date from the output of date.isoformat()"); + +#define DATETIME_DATE_FROMISOFORMAT_METHODDEF \ + {"fromisoformat", (PyCFunction)datetime_date_fromisoformat, METH_O|METH_CLASS, datetime_date_fromisoformat__doc__}, + static PyObject * iso_calendar_date_new_impl(PyTypeObject *type, int year, int week, int weekday); @@ -144,4 +153,4 @@ datetime_datetime_now(PyTypeObject *type, PyObject *const *args, Py_ssize_t narg exit: return return_value; } -/*[clinic end generated code: output=a78f8891b2c32698 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=cc394af4e25d266a input=a9049054013a1b77]*/ From d0eac8d99ae7c395e0c9db8565186a1ffc5ac610 Mon Sep 17 00:00:00 2001 From: hauntsaninja <> Date: Mon, 18 May 2020 22:27:17 -0700 Subject: [PATCH 03/11] datetime.date.fromisocalendar Note that this will now throw OverflowError instead of ValueError when using the C version of datetime. There is precedent for this, e.g., datetime.date.fromordinal will throw an OverflowError with the C module but ValueError with the Python. --- Lib/test/datetimetester.py | 3 -- Modules/_datetimemodule.c | 40 ++++++++---------- Modules/clinic/_datetimemodule.c.h | 65 +++++++++++++++++++++++++++++- 3 files changed, 81 insertions(+), 27 deletions(-) diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py index a9741d6d4062f4..bcda9a3700d957 100644 --- a/Lib/test/datetimetester.py +++ b/Lib/test/datetimetester.py @@ -1909,9 +1909,6 @@ def test_fromisocalendar_value_errors(self): (10000, 1, 1), (0, 1, 1), (9999999, 1, 1), - (2<<32, 1, 1), - (2019, 2<<32, 1), - (2019, 1, 2<<32), ] for isocal in isocals: diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index 69ba4f033857e9..6e875f0193b4e0 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -3022,25 +3022,24 @@ datetime_date_fromisoformat(PyTypeObject *type, PyObject *date_string) } -static PyObject * -date_fromisocalendar(PyObject *cls, PyObject *args, PyObject *kw) -{ - static char *keywords[] = { - "year", "week", "day", NULL - }; +/*[clinic input] +@classmethod +datetime.date.fromisocalendar - int year, week, day; - if (PyArg_ParseTupleAndKeywords(args, kw, "iii:fromisocalendar", - keywords, - &year, &week, &day) == 0) { - if (PyErr_ExceptionMatches(PyExc_OverflowError)) { - PyErr_Format(PyExc_ValueError, - "ISO calendar component out of range"); + year: int + week: int + day: int - } - return NULL; - } +int, int, int -> Construct a date from the ISO year, week number and weekday. + +This is the inverse of the date.isocalendar() function +[clinic start generated code]*/ +static PyObject * +datetime_date_fromisocalendar_impl(PyTypeObject *type, int year, int week, + int day) +/*[clinic end generated code: output=7b26e15115d24df6 input=f13669bbed6c8bb6]*/ +{ // Year is bounded to 0 < year < 10000 because 9999-12-31 is (9999, 52, 5) if (year < MINYEAR || year > MAXYEAR) { PyErr_Format(PyExc_ValueError, "Year is out of range: %d", year); @@ -3078,7 +3077,7 @@ date_fromisocalendar(PyObject *cls, PyObject *args, PyObject *kw) ord_to_ymd(day_1 + day_offset, &year, &month, &day); - return new_date_subclass_ex(year, month, day, cls); + return new_date_subclass_ex(year, month, day, (PyObject *) type); } @@ -3503,12 +3502,7 @@ static PyMethodDef date_methods[] = { DATETIME_DATE_FROMTIMESTAMP_METHODDEF DATETIME_DATE_FROMORDINAL_METHODDEF DATETIME_DATE_FROMISOFORMAT_METHODDEF - - {"fromisocalendar", (PyCFunction)(void(*)(void))date_fromisocalendar, - METH_VARARGS | METH_KEYWORDS | METH_CLASS, - PyDoc_STR("int, int, int -> Construct a date from the ISO year, week " - "number and weekday.\n\n" - "This is the inverse of the date.isocalendar() function")}, + DATETIME_DATE_FROMISOCALENDAR_METHODDEF {"today", (PyCFunction)date_today, METH_NOARGS | METH_CLASS, PyDoc_STR("Current date or datetime: same as " diff --git a/Modules/clinic/_datetimemodule.c.h b/Modules/clinic/_datetimemodule.c.h index f5133e35747b01..89b494e0cb3592 100644 --- a/Modules/clinic/_datetimemodule.c.h +++ b/Modules/clinic/_datetimemodule.c.h @@ -58,6 +58,69 @@ PyDoc_STRVAR(datetime_date_fromisoformat__doc__, #define DATETIME_DATE_FROMISOFORMAT_METHODDEF \ {"fromisoformat", (PyCFunction)datetime_date_fromisoformat, METH_O|METH_CLASS, datetime_date_fromisoformat__doc__}, +PyDoc_STRVAR(datetime_date_fromisocalendar__doc__, +"fromisocalendar($type, /, year, week, day)\n" +"--\n" +"\n" +"int, int, int -> Construct a date from the ISO year, week number and weekday.\n" +"\n" +"This is the inverse of the date.isocalendar() function"); + +#define DATETIME_DATE_FROMISOCALENDAR_METHODDEF \ + {"fromisocalendar", (PyCFunction)(void(*)(void))datetime_date_fromisocalendar, METH_FASTCALL|METH_KEYWORDS|METH_CLASS, datetime_date_fromisocalendar__doc__}, + +static PyObject * +datetime_date_fromisocalendar_impl(PyTypeObject *type, int year, int week, + int day); + +static PyObject * +datetime_date_fromisocalendar(PyTypeObject *type, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames) +{ + PyObject *return_value = NULL; + static const char * const _keywords[] = {"year", "week", "day", NULL}; + static _PyArg_Parser _parser = {NULL, _keywords, "fromisocalendar", 0}; + PyObject *argsbuf[3]; + int year; + int week; + int day; + + args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf); + if (!args) { + goto exit; + } + if (PyFloat_Check(args[0])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + year = _PyLong_AsInt(args[0]); + if (year == -1 && PyErr_Occurred()) { + goto exit; + } + if (PyFloat_Check(args[1])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + week = _PyLong_AsInt(args[1]); + if (week == -1 && PyErr_Occurred()) { + goto exit; + } + if (PyFloat_Check(args[2])) { + PyErr_SetString(PyExc_TypeError, + "integer argument expected, got float" ); + goto exit; + } + day = _PyLong_AsInt(args[2]); + if (day == -1 && PyErr_Occurred()) { + goto exit; + } + return_value = datetime_date_fromisocalendar_impl(type, year, week, day); + +exit: + return return_value; +} + static PyObject * iso_calendar_date_new_impl(PyTypeObject *type, int year, int week, int weekday); @@ -153,4 +216,4 @@ datetime_datetime_now(PyTypeObject *type, PyObject *const *args, Py_ssize_t narg exit: return return_value; } -/*[clinic end generated code: output=cc394af4e25d266a input=a9049054013a1b77]*/ +/*[clinic end generated code: output=243be40ba706f2b9 input=a9049054013a1b77]*/ From 5d9b7de4db83b4b39675960522d6d6a7c002fc14 Mon Sep 17 00:00:00 2001 From: hauntsaninja <> Date: Mon, 18 May 2020 22:57:26 -0700 Subject: [PATCH 04/11] datetime.today --- Modules/_datetimemodule.c | 28 +++++++++++++++++----------- Modules/clinic/_datetimemodule.c.h | 22 +++++++++++++++++++++- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index 6e875f0193b4e0..403015756e7408 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -2876,13 +2876,18 @@ date_fromtimestamp(PyObject *cls, PyObject *obj) cls); } -/* Return new date from current time. - * We say this is equivalent to fromtimestamp(time.time()), and the - * only way to be sure of that is to *call* time.time(). That's not - * generally the same as calling C's time. - */ +/*[clinic input] +@classmethod +datetime.date.today + +Return new date from current time. + +Same as self.__class__.fromtimestamp(time.time()) +[clinic start generated code]*/ + static PyObject * -date_today(PyObject *cls, PyObject *dummy) +datetime_date_today_impl(PyTypeObject *type) +/*[clinic end generated code: output=d5474697df6b251c input=22b09b5b306fdccb]*/ { PyObject *time; PyObject *result; @@ -2897,8 +2902,12 @@ date_today(PyObject *cls, PyObject *dummy) * datetime.fromtimestamp. That's why we need all the accuracy * time.time() delivers; if someone were gonzo about optimization, * date.today() could get away with plain C time(). + * Besides, we claim that this method is equivalent to + * fromtimestamp(time.time()), and the only way to be of that is to *call* + * time.time(). That's not generally the same as calling C's time. */ - result = _PyObject_CallMethodIdOneArg(cls, &PyId_fromtimestamp, time); + result = _PyObject_CallMethodIdOneArg((PyObject *) type, + &PyId_fromtimestamp, time); Py_DECREF(time); return result; } @@ -3503,10 +3512,7 @@ static PyMethodDef date_methods[] = { DATETIME_DATE_FROMORDINAL_METHODDEF DATETIME_DATE_FROMISOFORMAT_METHODDEF DATETIME_DATE_FROMISOCALENDAR_METHODDEF - - {"today", (PyCFunction)date_today, METH_NOARGS | METH_CLASS, - PyDoc_STR("Current date or datetime: same as " - "self.__class__.fromtimestamp(time.time()).")}, + DATETIME_DATE_TODAY_METHODDEF /* Instance methods: */ diff --git a/Modules/clinic/_datetimemodule.c.h b/Modules/clinic/_datetimemodule.c.h index 89b494e0cb3592..e2b6d0a7cbb854 100644 --- a/Modules/clinic/_datetimemodule.c.h +++ b/Modules/clinic/_datetimemodule.c.h @@ -2,6 +2,26 @@ preserve [clinic start generated code]*/ +PyDoc_STRVAR(datetime_date_today__doc__, +"today($type, /)\n" +"--\n" +"\n" +"Return new date from current time.\n" +"\n" +"Same as self.__class__.fromtimestamp(time.time())"); + +#define DATETIME_DATE_TODAY_METHODDEF \ + {"today", (PyCFunction)datetime_date_today, METH_NOARGS|METH_CLASS, datetime_date_today__doc__}, + +static PyObject * +datetime_date_today_impl(PyTypeObject *type); + +static PyObject * +datetime_date_today(PyTypeObject *type, PyObject *Py_UNUSED(ignored)) +{ + return datetime_date_today_impl(type); +} + PyDoc_STRVAR(datetime_date_fromtimestamp__doc__, "fromtimestamp($type, timestamp, /)\n" "--\n" @@ -216,4 +236,4 @@ datetime_datetime_now(PyTypeObject *type, PyObject *const *args, Py_ssize_t narg exit: return return_value; } -/*[clinic end generated code: output=243be40ba706f2b9 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=1c55ed8e872d3207 input=a9049054013a1b77]*/ From 049738382cc7d358dec69f8661a1f197bf85368e Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Tue, 19 May 2020 06:32:12 +0000 Subject: [PATCH 05/11] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20b?= =?UTF-8?q?lurb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../NEWS.d/next/Library/2020-05-19-06-32-11.bpo-20177.BwGrIX.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2020-05-19-06-32-11.bpo-20177.BwGrIX.rst diff --git a/Misc/NEWS.d/next/Library/2020-05-19-06-32-11.bpo-20177.BwGrIX.rst b/Misc/NEWS.d/next/Library/2020-05-19-06-32-11.bpo-20177.BwGrIX.rst new file mode 100644 index 00000000000000..3ead3b617ca5db --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-05-19-06-32-11.bpo-20177.BwGrIX.rst @@ -0,0 +1 @@ +Convert :class:`datetime.date` class methods to use Argument Clinic. \ No newline at end of file From c1a2b1efd140e6d68d33df8321e4e9cd1b9147f9 Mon Sep 17 00:00:00 2001 From: hauntsaninja <> Date: Wed, 3 Jun 2020 18:08:27 -0700 Subject: [PATCH 06/11] re-run argument clinic --- Modules/clinic/_datetimemodule.c.h | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/Modules/clinic/_datetimemodule.c.h b/Modules/clinic/_datetimemodule.c.h index 32ef8216a33aeb..3b047c4b621c32 100644 --- a/Modules/clinic/_datetimemodule.c.h +++ b/Modules/clinic/_datetimemodule.c.h @@ -54,11 +54,6 @@ datetime_date_fromordinal(PyTypeObject *type, PyObject *arg) PyObject *return_value = NULL; int ordinal; - if (PyFloat_Check(arg)) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } ordinal = _PyLong_AsInt(arg); if (ordinal == -1 && PyErr_Occurred()) { goto exit; @@ -108,29 +103,14 @@ datetime_date_fromisocalendar(PyTypeObject *type, PyObject *const *args, Py_ssiz if (!args) { goto exit; } - if (PyFloat_Check(args[0])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } year = _PyLong_AsInt(args[0]); if (year == -1 && PyErr_Occurred()) { goto exit; } - if (PyFloat_Check(args[1])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } week = _PyLong_AsInt(args[1]); if (week == -1 && PyErr_Occurred()) { goto exit; } - if (PyFloat_Check(args[2])) { - PyErr_SetString(PyExc_TypeError, - "integer argument expected, got float" ); - goto exit; - } day = _PyLong_AsInt(args[2]); if (day == -1 && PyErr_Occurred()) { goto exit; @@ -221,4 +201,4 @@ datetime_datetime_now(PyTypeObject *type, PyObject *const *args, Py_ssize_t narg exit: return return_value; } -/*[clinic end generated code: output=f61310936e3d8091 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=6b92790e74defece input=a9049054013a1b77]*/ From e6f75728cd4d11bf40f62182d43b85096155c232 Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Fri, 21 Jan 2022 01:12:30 -0800 Subject: [PATCH 07/11] Update Modules/_datetimemodule.c Co-authored-by: Tal Einat <532281+taleinat@users.noreply.github.com> --- Modules/_datetimemodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index 54f8d3f4d5fe63..ae50c88b7c6f75 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -3041,7 +3041,7 @@ datetime.date.fromisocalendar int, int, int -> Construct a date from the ISO year, week number and weekday. -This is the inverse of the date.isocalendar() function +This is the inverse of the date.isocalendar() function. [clinic start generated code]*/ static PyObject * From 11f83fd506b901989745e9c3dd380dd1b4bcc929 Mon Sep 17 00:00:00 2001 From: hauntsaninja <> Date: Fri, 21 Jan 2022 01:13:16 -0800 Subject: [PATCH 08/11] Remove NEWS entry --- .../NEWS.d/next/Library/2020-05-19-06-32-11.bpo-20177.BwGrIX.rst | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Misc/NEWS.d/next/Library/2020-05-19-06-32-11.bpo-20177.BwGrIX.rst diff --git a/Misc/NEWS.d/next/Library/2020-05-19-06-32-11.bpo-20177.BwGrIX.rst b/Misc/NEWS.d/next/Library/2020-05-19-06-32-11.bpo-20177.BwGrIX.rst deleted file mode 100644 index 3ead3b617ca5db..00000000000000 --- a/Misc/NEWS.d/next/Library/2020-05-19-06-32-11.bpo-20177.BwGrIX.rst +++ /dev/null @@ -1 +0,0 @@ -Convert :class:`datetime.date` class methods to use Argument Clinic. \ No newline at end of file From 188130b5afd533629e42b8edcabf50b0f1ef9c07 Mon Sep 17 00:00:00 2001 From: hauntsaninja <> Date: Fri, 21 Jan 2022 01:14:28 -0800 Subject: [PATCH 09/11] Fix datetime.date.today docstring --- Modules/_datetimemodule.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index ae50c88b7c6f75..9e6b55749da83f 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -2880,7 +2880,7 @@ date_fromtimestamp(PyObject *cls, PyObject *obj) @classmethod datetime.date.today -Return new date from current time. +Current date or datetime. Same as self.__class__.fromtimestamp(time.time()) [clinic start generated code]*/ From 0528066a674f3daacff29c4d9766b7c995cd3248 Mon Sep 17 00:00:00 2001 From: hauntsaninja <> Date: Fri, 21 Jan 2022 01:23:01 -0800 Subject: [PATCH 10/11] Re-run clinic --- Modules/_datetimemodule.c | 4 ++-- Modules/clinic/_datetimemodule.c.h | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index 9e6b55749da83f..c4a861ffb23934 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -2887,7 +2887,7 @@ Same as self.__class__.fromtimestamp(time.time()) static PyObject * datetime_date_today_impl(PyTypeObject *type) -/*[clinic end generated code: output=d5474697df6b251c input=22b09b5b306fdccb]*/ +/*[clinic end generated code: output=d5474697df6b251c input=0dff9bfe3e2274b2]*/ { PyObject *time; PyObject *result; @@ -3047,7 +3047,7 @@ This is the inverse of the date.isocalendar() function. static PyObject * datetime_date_fromisocalendar_impl(PyTypeObject *type, int year, int week, int day) -/*[clinic end generated code: output=7b26e15115d24df6 input=f13669bbed6c8bb6]*/ +/*[clinic end generated code: output=7b26e15115d24df6 input=e3daae6e2b75f1be]*/ { // Year is bounded to 0 < year < 10000 because 9999-12-31 is (9999, 52, 5) if (year < MINYEAR || year > MAXYEAR) { diff --git a/Modules/clinic/_datetimemodule.c.h b/Modules/clinic/_datetimemodule.c.h index 3b047c4b621c32..e0e0ccb22ba058 100644 --- a/Modules/clinic/_datetimemodule.c.h +++ b/Modules/clinic/_datetimemodule.c.h @@ -6,7 +6,7 @@ PyDoc_STRVAR(datetime_date_today__doc__, "today($type, /)\n" "--\n" "\n" -"Return new date from current time.\n" +"Current date or datetime.\n" "\n" "Same as self.__class__.fromtimestamp(time.time())"); @@ -79,7 +79,7 @@ PyDoc_STRVAR(datetime_date_fromisocalendar__doc__, "\n" "int, int, int -> Construct a date from the ISO year, week number and weekday.\n" "\n" -"This is the inverse of the date.isocalendar() function"); +"This is the inverse of the date.isocalendar() function."); #define DATETIME_DATE_FROMISOCALENDAR_METHODDEF \ {"fromisocalendar", (PyCFunction)(void(*)(void))datetime_date_fromisocalendar, METH_FASTCALL|METH_KEYWORDS|METH_CLASS, datetime_date_fromisocalendar__doc__}, @@ -201,4 +201,4 @@ datetime_datetime_now(PyTypeObject *type, PyObject *const *args, Py_ssize_t narg exit: return return_value; } -/*[clinic end generated code: output=6b92790e74defece input=a9049054013a1b77]*/ +/*[clinic end generated code: output=45e5f93fa01f71fa input=a9049054013a1b77]*/ From d6c87598c302f79b3d64f27a2b1d7d574597b836 Mon Sep 17 00:00:00 2001 From: hauntsaninja <> Date: Fri, 21 Jan 2022 01:50:38 -0800 Subject: [PATCH 11/11] Use dtstr instead of date_string --- Modules/_datetimemodule.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index c4a861ffb23934..bafce17b1bcc1c 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -2984,19 +2984,19 @@ datetime_date_fromordinal_impl(PyTypeObject *type, int ordinal) @classmethod datetime.date.fromisoformat - date_string: object + date_string as dtstr: object / str -> Construct a date from the output of date.isoformat() [clinic start generated code]*/ static PyObject * -datetime_date_fromisoformat(PyTypeObject *type, PyObject *date_string) -/*[clinic end generated code: output=6657c70f3442350a input=cecf94602c2e7fd8]*/ +datetime_date_fromisoformat(PyTypeObject *type, PyObject *dtstr) +/*[clinic end generated code: output=0c55fa0175e3e94b input=6bebe824e582fd1e]*/ { - assert(date_string != NULL); + assert(dtstr != NULL); - if (!PyUnicode_Check(date_string)) { + if (!PyUnicode_Check(dtstr)) { PyErr_SetString(PyExc_TypeError, "fromisoformat: argument must be str"); return NULL; @@ -3004,7 +3004,7 @@ datetime_date_fromisoformat(PyTypeObject *type, PyObject *date_string) Py_ssize_t len; - const char *dt_ptr = PyUnicode_AsUTF8AndSize(date_string, &len); + const char *dt_ptr = PyUnicode_AsUTF8AndSize(dtstr, &len); if (dt_ptr == NULL) { goto invalid_string_error; } @@ -3026,7 +3026,7 @@ datetime_date_fromisoformat(PyTypeObject *type, PyObject *date_string) return new_date_subclass_ex(year, month, day, (PyObject *) type); invalid_string_error: - PyErr_Format(PyExc_ValueError, "Invalid isoformat string: %R", date_string); + PyErr_Format(PyExc_ValueError, "Invalid isoformat string: %R", dtstr); return NULL; }