Skip to content

Commit 9aa34f1

Browse files
bpo-41867: List options for timespec in docstrings of isoformat methods (GH-22418)
(cherry picked from commit 5230131) Co-authored-by: Ram Rachum <[email protected]>
1 parent 4b982e0 commit 9aa34f1

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

Lib/datetime.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1418,7 +1418,8 @@ def isoformat(self, timespec='auto'):
14181418
part is omitted if self.microsecond == 0.
14191419
14201420
The optional argument timespec specifies the number of additional
1421-
terms of the time to include.
1421+
terms of the time to include. Valid options are 'auto', 'hours',
1422+
'minutes', 'seconds', 'milliseconds' and 'microseconds'.
14221423
"""
14231424
s = _format_time(self._hour, self._minute, self._second,
14241425
self._microsecond, timespec)
@@ -1902,7 +1903,8 @@ def isoformat(self, sep='T', timespec='auto'):
19021903
time, default 'T'.
19031904
19041905
The optional argument timespec specifies the number of additional
1905-
terms of the time to include.
1906+
terms of the time to include. Valid options are 'auto', 'hours',
1907+
'minutes', 'seconds', 'milliseconds' and 'microseconds'.
19061908
"""
19071909
s = ("%04d-%02d-%02d%c" % (self._year, self._month, self._day, sep) +
19081910
_format_time(self._hour, self._minute, self._second,

Modules/_datetimemodule.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4539,7 +4539,10 @@ static PyMethodDef time_methods[] = {
45394539
{"isoformat", (PyCFunction)(void(*)(void))time_isoformat, METH_VARARGS | METH_KEYWORDS,
45404540
PyDoc_STR("Return string in ISO 8601 format, [HH[:MM[:SS[.mmm[uuu]]]]]"
45414541
"[+HH:MM].\n\n"
4542-
"timespec specifies what components of the time to include.\n")},
4542+
"The optional argument timespec specifies the number "
4543+
"of additional terms\nof the time to include. Valid "
4544+
"options are 'auto', 'hours', 'minutes',\n'seconds', "
4545+
"'milliseconds' and 'microseconds'.\n")},
45434546

45444547
{"strftime", (PyCFunction)(void(*)(void))time_strftime, METH_VARARGS | METH_KEYWORDS,
45454548
PyDoc_STR("format -> strftime() style string.")},
@@ -6246,9 +6249,10 @@ static PyMethodDef datetime_methods[] = {
62466249
"YYYY-MM-DDT[HH[:MM[:SS[.mmm[uuu]]]]][+HH:MM].\n"
62476250
"sep is used to separate the year from the time, and "
62486251
"defaults to 'T'.\n"
6249-
"timespec specifies what components of the time to include"
6250-
" (allowed values are 'auto', 'hours', 'minutes', 'seconds',"
6251-
" 'milliseconds', and 'microseconds').\n")},
6252+
"The optional argument timespec specifies the number "
6253+
"of additional terms\nof the time to include. Valid "
6254+
"options are 'auto', 'hours', 'minutes',\n'seconds', "
6255+
"'milliseconds' and 'microseconds'.\n")},
62526256

62536257
{"utcoffset", (PyCFunction)datetime_utcoffset, METH_NOARGS,
62546258
PyDoc_STR("Return self.tzinfo.utcoffset(self).")},

0 commit comments

Comments
 (0)