From 2cf017b68f7e5445acbf6491011315bef5242b30 Mon Sep 17 00:00:00 2001 From: Ram Rachum Date: Sat, 26 Sep 2020 19:46:39 +0300 Subject: [PATCH 1/3] bpo-41867: Show options for timespec in isoformat docstrings --- Lib/datetime.py | 6 ++++-- Modules/_datetimemodule.c | 12 ++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/Lib/datetime.py b/Lib/datetime.py index 3090978508c921..ea86bcb8b2388a 100644 --- a/Lib/datetime.py +++ b/Lib/datetime.py @@ -1421,7 +1421,8 @@ def isoformat(self, timespec='auto'): part is omitted if self.microsecond == 0. The optional argument timespec specifies the number of additional - terms of the time to include. + terms of the time to include. Valid options are 'auto', 'hours', + 'minutes', 'seconds', 'milliseconds' and 'microseconds'. """ s = _format_time(self._hour, self._minute, self._second, self._microsecond, timespec) @@ -1906,7 +1907,8 @@ def isoformat(self, sep='T', timespec='auto'): time, default 'T'. The optional argument timespec specifies the number of additional - terms of the time to include. + terms of the time to include. Valid options are 'auto', 'hours', + 'minutes', 'seconds', 'milliseconds' and 'microseconds'. """ s = ("%04d-%02d-%02d%c" % (self._year, self._month, self._day, sep) + _format_time(self._hour, self._minute, self._second, diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index 0631272429f4f1..a51ef637bdf5f8 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -4663,7 +4663,10 @@ static PyMethodDef time_methods[] = { {"isoformat", (PyCFunction)(void(*)(void))time_isoformat, METH_VARARGS | METH_KEYWORDS, PyDoc_STR("Return string in ISO 8601 format, [HH[:MM[:SS[.mmm[uuu]]]]]" "[+HH:MM].\n\n" - "timespec specifies what components of the time to include.\n")}, + "The optional argument timespec specifies the number of " + "additional terms of the time to include.\n" + "Valid options are 'auto', 'hours', 'minutes', " + "'seconds', 'milliseconds' and 'microseconds'.\n")}, {"strftime", (PyCFunction)(void(*)(void))time_strftime, METH_VARARGS | METH_KEYWORDS, PyDoc_STR("format -> strftime() style string.")}, @@ -6370,9 +6373,10 @@ static PyMethodDef datetime_methods[] = { "YYYY-MM-DDT[HH[:MM[:SS[.mmm[uuu]]]]][+HH:MM].\n" "sep is used to separate the year from the time, and " "defaults to 'T'.\n" - "timespec specifies what components of the time to include" - " (allowed values are 'auto', 'hours', 'minutes', 'seconds'," - " 'milliseconds', and 'microseconds').\n")}, + "The optional argument timespec specifies the number of " + "additional terms of the time to include.\n" + "Valid options are 'auto', 'hours', 'minutes', " + "'seconds', 'milliseconds' and 'microseconds'.\n")}, {"utcoffset", (PyCFunction)datetime_utcoffset, METH_NOARGS, PyDoc_STR("Return self.tzinfo.utcoffset(self).")}, From 2a51cb13492ac0fa35b6bf8ec42dc093517593a8 Mon Sep 17 00:00:00 2001 From: Tal Einat Date: Sat, 3 Oct 2020 13:07:34 +0300 Subject: [PATCH 2/3] more doc-string formatting tweaks in C code --- Modules/_datetimemodule.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index a51ef637bdf5f8..40b368d304b2e5 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -4663,10 +4663,10 @@ static PyMethodDef time_methods[] = { {"isoformat", (PyCFunction)(void(*)(void))time_isoformat, METH_VARARGS | METH_KEYWORDS, PyDoc_STR("Return string in ISO 8601 format, [HH[:MM[:SS[.mmm[uuu]]]]]" "[+HH:MM].\n\n" - "The optional argument timespec specifies the number of " - "additional terms of the time to include.\n" - "Valid options are 'auto', 'hours', 'minutes', " - "'seconds', 'milliseconds' and 'microseconds'.\n")}, + "The optional argument timespec specifies the number + "of additional terms\nof the time to include. Valid " + "options are 'auto', 'hours', 'minutes',\n'seconds', " + "'milliseconds' and 'microseconds'.\n")}, {"strftime", (PyCFunction)(void(*)(void))time_strftime, METH_VARARGS | METH_KEYWORDS, PyDoc_STR("format -> strftime() style string.")}, @@ -6373,10 +6373,10 @@ static PyMethodDef datetime_methods[] = { "YYYY-MM-DDT[HH[:MM[:SS[.mmm[uuu]]]]][+HH:MM].\n" "sep is used to separate the year from the time, and " "defaults to 'T'.\n" - "The optional argument timespec specifies the number of " - "additional terms of the time to include.\n" - "Valid options are 'auto', 'hours', 'minutes', " - "'seconds', 'milliseconds' and 'microseconds'.\n")}, + "The optional argument timespec specifies the number + "of additional terms\nof the time to include. Valid " + "options are 'auto', 'hours', 'minutes',\n'seconds', " + "'milliseconds' and 'microseconds'.\n")}, {"utcoffset", (PyCFunction)datetime_utcoffset, METH_NOARGS, PyDoc_STR("Return self.tzinfo.utcoffset(self).")}, From 21d117e5ef6b47206b8e6fe0bf768b1717e1aeaf Mon Sep 17 00:00:00 2001 From: Tal Einat Date: Sat, 3 Oct 2020 13:23:19 +0300 Subject: [PATCH 3/3] bah --- Modules/_datetimemodule.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/_datetimemodule.c b/Modules/_datetimemodule.c index 40b368d304b2e5..94868717e6a04c 100644 --- a/Modules/_datetimemodule.c +++ b/Modules/_datetimemodule.c @@ -4663,7 +4663,7 @@ static PyMethodDef time_methods[] = { {"isoformat", (PyCFunction)(void(*)(void))time_isoformat, METH_VARARGS | METH_KEYWORDS, PyDoc_STR("Return string in ISO 8601 format, [HH[:MM[:SS[.mmm[uuu]]]]]" "[+HH:MM].\n\n" - "The optional argument timespec specifies the number + "The optional argument timespec specifies the number " "of additional terms\nof the time to include. Valid " "options are 'auto', 'hours', 'minutes',\n'seconds', " "'milliseconds' and 'microseconds'.\n")}, @@ -6373,7 +6373,7 @@ static PyMethodDef datetime_methods[] = { "YYYY-MM-DDT[HH[:MM[:SS[.mmm[uuu]]]]][+HH:MM].\n" "sep is used to separate the year from the time, and " "defaults to 'T'.\n" - "The optional argument timespec specifies the number + "The optional argument timespec specifies the number " "of additional terms\nof the time to include. Valid " "options are 'auto', 'hours', 'minutes',\n'seconds', " "'milliseconds' and 'microseconds'.\n")},