Skip to content

Commit dfd52e7

Browse files
gh-97517: Add documentation links to datetime strftime/strptime docstrings (#138559)
* Add documentation links to datetime strftime/strptime docstrings - Add links to format codes documentation for all strftime methods - Add links to format codes documentation for all strptime methods - Addresses issue #97517 * Update C extension docstrings with format codes documentation * Regenerate clinic code for updated docstrings * Add clinic-generated header file for updated docstrings * Fix docstring spacing consistency in both Python and C files * Update Lib/_pydatetime.py Co-authored-by: Stan Ulbrych <[email protected]> --------- Co-authored-by: Stan Ulbrych <[email protected]>
1 parent 537133d commit dfd52e7

File tree

3 files changed

+62
-14
lines changed

3 files changed

+62
-14
lines changed

Lib/_pydatetime.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,11 @@ def fromisocalendar(cls, year, week, day):
10721072

10731073
@classmethod
10741074
def strptime(cls, date_string, format):
1075-
"""Parse string according to the given date format (like time.strptime())."""
1075+
"""Parse string according to the given date format (like time.strptime()).
1076+
1077+
For a list of supported format codes, see the documentation:
1078+
https://docs.python.org/3/library/datetime.html#format-codes
1079+
"""
10761080
import _strptime
10771081
return _strptime._strptime_datetime_date(cls, date_string, format)
10781082

@@ -1109,6 +1113,8 @@ def strftime(self, format):
11091113
Format using strftime().
11101114
11111115
Example: "%d/%m/%Y, %H:%M:%S"
1116+
For a list of supported format codes, see the documentation:
1117+
https://docs.python.org/3/library/datetime.html#format-codes
11121118
"""
11131119
return _wrap_strftime(self, format, self.timetuple())
11141120

@@ -1456,8 +1462,13 @@ def __new__(cls, hour=0, minute=0, second=0, microsecond=0, tzinfo=None, *, fold
14561462
return self
14571463

14581464
@classmethod
1465+
14591466
def strptime(cls, date_string, format):
1460-
"""Parse string according to the given time format (like time.strptime())."""
1467+
"""Parse string according to the given time format (like time.strptime()).
1468+
1469+
For a list of supported format codes, see the documentation:
1470+
https://docs.python.org/3/library/datetime.html#format-codes
1471+
"""
14611472
import _strptime
14621473
return _strptime._strptime_datetime_time(cls, date_string, format)
14631474

@@ -1650,6 +1661,9 @@ def fromisoformat(cls, time_string):
16501661
def strftime(self, format):
16511662
"""Format using strftime(). The date part of the timestamp passed
16521663
to underlying strftime should not be used.
1664+
1665+
For a list of supported format codes, see the documentation:
1666+
https://docs.python.org/3/library/datetime.html#format-codes
16531667
"""
16541668
# The year must be >= 1000 else Python's strftime implementation
16551669
# can raise a bogus exception.
@@ -2198,7 +2212,11 @@ def __str__(self):
21982212

21992213
@classmethod
22002214
def strptime(cls, date_string, format):
2201-
"""Parse string according to the given date and time format (like time.strptime())."""
2215+
"""Parse string according to the given time format (like time.strptime()).
2216+
2217+
For a list of supported format codes, see the documentation:
2218+
https://docs.python.org/3/library/datetime.html#format-codes
2219+
"""
22022220
import _strptime
22032221
return _strptime._strptime_datetime_datetime(cls, date_string, format)
22042222

Modules/_datetimemodule.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3468,12 +3468,15 @@ datetime.date.strptime
34683468
/
34693469
34703470
Parse string according to the given date format (like time.strptime()).
3471+
3472+
For a list of supported format codes, see the documentation:
3473+
https://docs.python.org/3/library/datetime.html#format-codes
34713474
[clinic start generated code]*/
34723475

34733476
static PyObject *
34743477
datetime_date_strptime_impl(PyTypeObject *type, PyObject *string,
34753478
PyObject *format)
3476-
/*[clinic end generated code: output=454d473bee2d5161 input=001904ab34f594a1]*/
3479+
/*[clinic end generated code: output=454d473bee2d5161 input=31d57bb789433e99]*/
34773480
{
34783481
PyObject *result;
34793482

@@ -3608,11 +3611,14 @@ datetime.date.strftime
36083611
Format using strftime().
36093612
36103613
Example: "%d/%m/%Y, %H:%M:%S".
3614+
3615+
For a list of supported format codes, see the documentation:
3616+
https://docs.python.org/3/library/datetime.html#format-codes
36113617
[clinic start generated code]*/
36123618

36133619
static PyObject *
36143620
datetime_date_strftime_impl(PyObject *self, PyObject *format)
3615-
/*[clinic end generated code: output=6529b70095e16778 input=72af55077e606ed8]*/
3621+
/*[clinic end generated code: output=6529b70095e16778 input=b6fd4a2ded27b557]*/
36163622
{
36173623
/* This method can be inherited, and needs to call the
36183624
* timetuple() method appropriate to self's class.
@@ -4711,12 +4717,15 @@ datetime.time.strptime
47114717
/
47124718
47134719
Parse string according to the given time format (like time.strptime()).
4720+
4721+
For a list of supported format codes, see the documentation:
4722+
https://docs.python.org/3/library/datetime.html#format-codes
47144723
[clinic start generated code]*/
47154724

47164725
static PyObject *
47174726
datetime_time_strptime_impl(PyTypeObject *type, PyObject *string,
47184727
PyObject *format)
4719-
/*[clinic end generated code: output=ae05a9bc0241d3bf input=6d0f263a5f94d78d]*/
4728+
/*[clinic end generated code: output=ae05a9bc0241d3bf input=82ba425ecacc54aa]*/
47204729
{
47214730
PyObject *result;
47224731

@@ -4891,11 +4900,14 @@ datetime.time.strftime
48914900
Format using strftime().
48924901
48934902
The date part of the timestamp passed to underlying strftime should not be used.
4903+
4904+
For a list of supported format codes, see the documentation:
4905+
https://docs.python.org/3/library/datetime.html#format-codes
48944906
[clinic start generated code]*/
48954907

48964908
static PyObject *
48974909
datetime_time_strftime_impl(PyDateTime_Time *self, PyObject *format)
4898-
/*[clinic end generated code: output=10f65af20e2a78c7 input=541934a2860f7db5]*/
4910+
/*[clinic end generated code: output=10f65af20e2a78c7 input=c4a5bbecd798654b]*/
48994911
{
49004912
PyObject *result;
49014913
PyObject *tuple;
@@ -5787,12 +5799,15 @@ datetime.datetime.strptime
57875799
/
57885800
57895801
Parse string according to the given date and time format (like time.strptime()).
5802+
5803+
For a list of supported format codes, see the documentation:
5804+
https://docs.python.org/3/library/datetime.html#format-codes
57905805
[clinic start generated code]*/
57915806

57925807
static PyObject *
57935808
datetime_datetime_strptime_impl(PyTypeObject *type, PyObject *string,
57945809
PyObject *format)
5795-
/*[clinic end generated code: output=af2c2d024f3203f5 input=d7597c7f5327117b]*/
5810+
/*[clinic end generated code: output=af2c2d024f3203f5 input=ef7807589f1d50e7]*/
57965811
{
57975812
PyObject *result;
57985813

Modules/clinic/_datetimemodule.c.h

Lines changed: 21 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)