Skip to content

Conversation

@gpshead
Copy link
Member

@gpshead gpshead commented Mar 1, 2024

Every four years people encounter this in part because it just isn't obvious that partial incomplete date parsing is not what datetime.strptime is designed for. This moves the footnote up to a more explanatory inline note with a code example.

We'd love the default year value for datetime to be different, but changing that could have other consequences for existing code. This documented workaround always works.


📚 Documentation preview 📚: https://cpython-previews--116179.org.readthedocs.build/

…datetime.

Every four years people encounter this because it just isn't obvious.
This moves the footnote up to a note with a code example.

We'd love to change the default year value for datetime but doing
that could have other consequences for existing code.  This documented
workaround *always* works.
@gpshead gpshead added the docs Documentation in the Doc dir label Mar 1, 2024
@gpshead gpshead self-assigned this Mar 1, 2024
@gpshead gpshead marked this pull request as ready for review March 1, 2024 08:05
@gpshead gpshead requested review from abalkin and pganssle as code owners March 1, 2024 08:05
@encukou
Copy link
Member

encukou commented Apr 2, 2024

Perhaps this should be only merged to the backport branches, not main.

@willingc
Copy link
Contributor

@gpshead Looks like this may need some tidying up if you are still interested.

@StanFromIreland
Copy link
Member

This has already been partially implemented (the smaller note) do we still want to add the larger note since its deprecated anyway?

@gpshead gpshead added needs backport to 3.12 only security fixes needs backport to 3.13 bugs and security fixes labels Mar 21, 2025
@gpshead gpshead moved this from Todo to In Progress in Docs PRs Mar 21, 2025
@gpshead gpshead removed the needs backport to 3.12 only security fixes label Mar 21, 2025
@serhiy-storchaka serhiy-storchaka added the needs backport to 3.14 bugs and security fixes label May 8, 2025
@gpshead gpshead added needs backport to 3.13 bugs and security fixes and removed needs backport to 3.13 bugs and security fixes labels Dec 21, 2025
@gpshead gpshead merged commit b8d3fdd into python:main Dec 21, 2025
34 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in Docs PRs Dec 21, 2025
@miss-islington-app
Copy link

Thanks @gpshead for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Dec 21, 2025
…datetime. (pythonGH-116179)

* pythongh-70647: Better promote how to safely parse yearless dates in datetime.

Every four years people encounter this because it just isn't obvious.
This moves the footnote up to a note with a code example.

We'd love to change the default year value for datetime but doing
that could have other consequences for existing code.  This documented
workaround *always* works.

* doctest code within note is bad, dedent.

* Update to match the error message.

* remove no longer referenced footnote

* ignore the warning in the doctest

* use Petr's suggestion for the docs to hide the warning processing

* cover date.strptime (3.14) as well
(cherry picked from commit b8d3fddba6e96e693ced0d3b8f6ddbd61428fd32)

Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
@bedevere-app
Copy link

bedevere-app bot commented Dec 21, 2025

GH-143037 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Dec 21, 2025
@gpshead
Copy link
Member Author

gpshead commented Dec 21, 2025

I realize we may simplify the text around this when we actually do the deprecation behavior change (which we could choose to do now that we're 3.15 though it's nicer to wait longer). But having the detail in the docs and the backport to the stable docs still seems good so I fixed this up. a backport to 3.13 docs will need to be manual due to the added method in 3.14.

gpshead added a commit that referenced this pull request Dec 21, 2025
… datetime. (GH-116179) (#143037)

gh-70647: Better promote how to safely parse yearless dates in datetime. (GH-116179)

* gh-70647: Better promote how to safely parse yearless dates in datetime.

Every four years people encounter this because it just isn't obvious.
This moves the footnote up to a note with a code example.

We'd love to change the default year value for datetime but doing
that could have other consequences for existing code.  This documented
workaround *always* works.

* doctest code within note is bad, dedent.

* Update to match the error message.

* remove no longer referenced footnote

* ignore the warning in the doctest

* use Petr's suggestion for the docs to hide the warning processing

* cover date.strptime (3.14) as well
(cherry picked from commit b8d3fdd)

Co-authored-by: Gregory P. Smith <68491+gpshead@users.noreply.github.com>
gpshead added a commit to gpshead/cpython that referenced this pull request Dec 21, 2025
…datetime. (pythonGH-116179)

* pythongh-70647: Better promote how to safely parse yearless dates in datetime.

Every four years people encounter this because it just isn't obvious.
This moves the footnote up to a note with a code example.

We'd love to change the default year value for datetime but doing
that could have other consequences for existing code.  This documented
workaround *always* works.

* doctest code within note is bad, dedent.

* Update to match the error message.

* remove no longer referenced footnote

* ignore the warning in the doctest

* use Petr's suggestion for the docs to hide the warning processing

* cover date.strptime (3.14) as well
@bedevere-app
Copy link

bedevere-app bot commented Dec 21, 2025

GH-143038 is a backport of this pull request to the 3.13 branch.

gpshead added a commit that referenced this pull request Dec 21, 2025
… datetime. (GH-116179) (#143038)

* gh-70647: Better promote how to safely parse yearless dates in datetime. (GH-116179)

* gh-70647: Better promote how to safely parse yearless dates in datetime.

Every four years people encounter this because it just isn't obvious.
This moves the footnote up to a note with a code example.

We'd love to change the default year value for datetime but doing
that could have other consequences for existing code.  This documented
workaround *always* works.

* doctest code within note is bad, dedent.

* Update to match the error message.

* remove no longer referenced footnote

* ignore the warning in the doctest

* use Petr's suggestion for the docs to hide the warning processing

* cover date.strptime (3.14) as well

* remove date.strptime mentions from 3.14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation in the Doc dir skip news

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

7 participants