https://github.com/python/cpython/commit/d621204d8743895a488da7421ab549ba0a51fe22
commit: d621204d8743895a488da7421ab549ba0a51fe22
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: Mariatta <[email protected]>
date: 2026-10-20T13:30:21-07:00
summary:

[3.14] gh-124549: Document that `strptime()` uses the last directive when a 
time unit is over-specified (GH-125009) (#159951)

gh-124549: Document that `strptime()` uses the last directive when a time unit 
is over-specified (GH-125009)

* Add a note that when over-specifying datetime format, only the last directive 
gets used.

* adjust and reorganize the notes location, fast forward to latest.

* Update Doc/library/datetime.rst



---------
(cherry picked from commit fd6ed15a894dcc426da3d4d6cc9f297573b2c83e)

Co-authored-by: Mariatta <[email protected]>
Co-authored-by: Stan Ulbrych <[email protected]>

files:
M Doc/library/datetime.rst

diff --git a/Doc/library/datetime.rst b/Doc/library/datetime.rst
index 5e85da49e1c3b8..e6c04fff1c5555 100644
--- a/Doc/library/datetime.rst
+++ b/Doc/library/datetime.rst
@@ -2703,6 +2703,13 @@ in the format string will be pulled from the default 
value.
    the default year of 1900 is *not* a leap year.  Always add a default leap
    year to partial date strings before parsing.
 
+.. note::
+   If a :meth:`~.datetime.strptime` format string contains more than
+   one directive for the same field, for example both ``%Y`` and ``%y``,
+   every directive must still match the input, but only the value of the
+   last one is used. For example, parsing ``200099`` with ``%Y%y`` gives
+   the year 1999. Repeating the same directive, like ``%Y%Y``, raises an error.
+
 .. testsetup::
 
     # doctest seems to turn the warning into an error which makes it

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to