Visitar URL original
GH-70647: Deprecate strptime day of month parsing without a year present to avoid leap-year bugs by gpshead · Pull Request #117107 · python/cpython · GitHub
Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
adjust example code comments.
To passively encourage people to include such comments in their own code
when adopting this mitigation...
  • Loading branch information
gpshead committed Apr 1, 2024
commit d4c994eb1a378198b540cb7688cf6d46cc0c2b4f
4 changes: 2 additions & 2 deletions Doc/library/datetime.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1094,7 +1094,7 @@ Other constructors, all class methods:

>>> from datetime import datetime
>>> date_string = "02/29"
>>> when = datetime.strptime(f"{date_string};1984", "%m/%d;%Y")
>>> when = datetime.strptime(f"{date_string};1984", "%m/%d;%Y") # Avoids leap year bug.
>>> when.strftime("%B %d") # doctest: +SKIP
Comment thread
pganssle marked this conversation as resolved.
'February 29'

Expand Down Expand Up @@ -2682,7 +2682,7 @@ Notes:
exception when it encounters leap day because the default year used by the
parser is not a leap year. Users run into this bug every four years...

>>> strptime(f"{month_day};1984", "%m/%d;%Y") # problem mitigated!
>>> strptime(f"{month_day};1984", "%m/%d;%Y") # No leap year bug.
Comment thread
encukou marked this conversation as resolved.
Outdated

.. deprecated-removed:: 3.13 3.15
:meth:`~.datetime.strptime` calls using a format string containing
Expand Down