Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

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 pganssle and abalkin as code owners March 1, 2024 08:05
>>> datetime.strptime(value, "%m/%d")
Traceback (most recent call last):
...
ValueError: day is out of range for month
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will need updating after your other PR is merged :) (so beware of the potential merge race between the two)

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting changes docs Documentation in the Doc dir skip news
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

5 participants