-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
gh-124529: Fix _strptime to make %c/%x accept a year with fewer digits
#124778
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
Open
zuo
wants to merge
25
commits into
python:main
Choose a base branch
from
zuo:strptime-c-and-y-fix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+289
−8
Open
Changes from 2 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
827db45
gh-124529: Fix _strptime to make %c/%x accept year with fewer digits
zuo 1d916a0
Add the blurb
zuo a4ba3c9
Fix/improve (and shorten) the blurb
zuo cef0722
Fix/improve/refactor tests and restrict their scope
zuo 6556bdf
Test fail message fixes
zuo 56c84dc
Continue enhancing/improving tests
zuo b42783c
Improve docstring
zuo 97b523e
Add a suitable mention in the docs + improve blurb
zuo 6c2addf
Docstring edit
zuo fb32c03
Edit the mention in the docs
zuo 722efe4
Minor docs edit
zuo 7b46a48
Fix/improve tests
zuo 3d4116a
Shorten blurb again
zuo 8eac106
Minor docs edit
zuo 1956662
Docstring edit
zuo a77c3da
Docs edit
zuo b3b161f
Docstring edit
zuo 949e66a
Minor test improvements/refactoring
zuo 059d4c5
Add `time.strptime()`-dedicated test
zuo 95753ac
Minor test improvements/refactoring
zuo ed4582b
Merge branch 'main' into strptime-c-and-y-fix
zuo 990b075
Minor test improvement
zuo ecc359d
Test improvements/refactoring
zuo 6d690ca
Minor refactoring
zuo 4ad1062
Merge branch 'main' into strptime-c-and-y-fix
zuo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 7 additions & 9 deletions
16
Misc/NEWS.d/next/Library/2024-09-30-04-49-22.gh-issue-124529.hDDlMH.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,7 @@ | ||
| Fix :meth:`datetime.datetime.strptime`, :meth:`datetime.date.strptime` as | ||
| well as :func:`time.strptime` (by modifying :class:`_strptime.TimeRE`) to | ||
| make ``%c`` and ``%x`` accept year number representations consisting of | ||
| fewer digits than the usual four or two (note that nothing changes for | ||
| ``%Y`` and ``%y``). Thanks to that, certain ``strftime/strptime`` round | ||
| trips (such as ``datetime.strptime(dt.strftime("%c"), "%c"))`` for | ||
| ``dt.year`` less than 1000) no longer raise ``ValueError`` for some | ||
| locales/platforms (this was the case, e.g., on Linux -- for various | ||
| locales, including ``C``/``C.UTF-8``). | ||
| Fix :meth:`datetime.datetime.strptime`, :meth:`datetime.date.strptime` | ||
| and :func:`time.strptime` (by altering the underlying mechanism) to make | ||
| ``%c``/``%x`` accept year numbers with fewer digits than the usual 4 or | ||
| 2 (not zero-padded), so that some ``strftime/strptime`` round trip cases | ||
| (e.g., ``date.strptime(d.strftime('%c'),'%c'))`` for ``d.year < 1000``, | ||
| with C-like locales on Linux) no longer raise :exc:`!ValueError`. Patch | ||
| by Jan Kaliszewski. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should write this
This will be more concise and intuitive.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I've shortened it; yet I'd prefer to keep the information that the fix prevents the error for certain cases of a
strftime/strptimeround trip (this is the key element of the gh-124529 issue's description).