Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32k
gh-102450: Add ISO-8601 alternative for midnight tofromisoformat()
calls.#105856
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
bedevere-bot commentedJun 16, 2023
Most changes to Pythonrequire a NEWS entry. Please add it using theblurb_it web app or theblurb command-line tool. |
ghost commentedJun 16, 2023 • edited by ghost
Loading Uh oh!
There was an error while loading.Please reload this page.
edited by ghost
Uh oh!
There was an error while loading.Please reload this page.
The PEP that explains it was linked on the issue:#102450 (comment) Basically, (I believe) you need to implement it in both places but only the C version is used by CPython. If you add tests they should run on both implementations so you can ensure you've done things correctly. You should also be able to |
TizzySaurus commentedJun 17, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Thanks@wookie184, that makes sense 😄 I do have a query though: the tests that I added in 311f914 are actually passing ( EDIT: I've since added the Python implementation, but am still not convinced that the Python implementation is getting tested locally (seems to be here on GitHub though). |
TizzySaurus commentedJun 17, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I've also just noticed that the >>>fromdatetimeimportdatetimeasc_datetime>>>c_datetime.fromisoformat("2023-01-32T24:00:00")Traceback (mostrecentcalllast):File"<stdin>",line1,in<module>ValueError:dayisoutofrangeformonth vs >>>from_pydatetimeimportdatetimeaspy_datetime>>>py_datetime.fromisoformat("2023-01-32T24:00:00")Traceback (mostrecentcalllast):File"<stdin>",line1,in<module>File"/Users/xxx/Documents/personal/cpython/Lib/_pydatetime.py",line1906,infromisoformatreturncls(*(date_components+time_components))^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File"/Users/xxx/Documents/personal/cpython/Lib/_pydatetime.py",line1717,in__new__year,month,day=_check_date_fields(year,month,day)^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^File"/Users/xxx/Documents/personal/cpython/Lib/_pydatetime.py",line545,in_check_date_fieldsraiseValueError('day must be in 1..%d'%dim,day)ValueError: ('day must be in 1..31',32) Note how |
We can handle this separately. |
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.
This looks great! Do you want to add yourself to the ACKS file and/or to the patch name, so you get credit? (This is optional)
Also can you rebase against main?
Misc/NEWS.d/next/Library/2023-06-16-14-52-00.gh-issue-102450.MfeR6A.rst OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
vstinner left a comment• edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
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.
LGTM. I like how invalid inputs (month 13, non-zero minute, etc.) are checked: it's smart (and keep the code short) :-) I also like tests which seem to cover all cases.
About the feature itself, I trust@pganssle's opinion to decide if we should implement it or not.
…n 24hrs has non-zero time component(s)
26338f5
to1b65671
CompareTizzySaurus commentedSep 25, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Think I've done this correctly, so hopefully should be good now 🙂 |
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.
Oh nice, the code handles also well the maximum date:
$ ./python>>> import datetime>>> datetime.datetime.fromisoformat('9999-12-31T24:00:00')ValueError: year 10000 is out of range
Uh oh!
There was an error while loading.Please reload this page.
b0c6cf5
intopython:mainUh oh!
There was an error while loading.Please reload this page.
* main: (69 commits) Add "annotate" SET_FUNCTION_ATTRIBUTE bit to dis. (python#124566)pythongh-124412: Add helpers for converting annotations to source format (python#124551)pythongh-119180: Disallow instantiation of ConstEvaluator objects (python#124561) For-else deserves its own section in the tutorial (python#123946) Add 3.13 as a version option to the crash issue template (python#124560)pythongh-123242: Note that type.__annotations__ may not exist (python#124557)pythongh-119180: Make FORWARDREF format look at __annotations__ first (python#124479)pythonGH-58058: Add quick reference for `ArgumentParser` to argparse docs (pythongh-124227)pythongh-41431: Add `datetime.time.strptime()` and `datetime.date.strptime()` (python#120752)pythongh-102450: Add ISO-8601 alternative for midnight to `fromisoformat()` calls. (python#105856)pythongh-124370: Add "howto" for free-threaded Python (python#124371)pythongh-121277: Allow `.. versionadded:: next` in docs (pythonGH-121278)pythongh-119400: make_ssl_certs: update reference test data automatically, pass in expiration dates as parameterspython#119400 (pythonGH-119401)pythongh-119180: Avoid going through AST and eval() when possible in annotationlib (python#124337)pythongh-124448: Update Windows builds to use Tcl/Tk 8.6.15 (pythonGH-124449)pythongh-123884 Tee of tee was not producing n independent iterators (pythongh-124490)pythongh-124378: Update test_ttk for Tcl/Tk 8.6.15 (pythonGH-124542)pythongh-124513: Check args in framelocalsproxy_new() (python#124515)pythongh-101100: Add a table of class attributes to the "Custom classes" section of the data model docs (python#124480) Doc: Use ``major.minor`` for documentation distribution archive filenames (python#124489) ...
Uh oh!
There was an error while loading.Please reload this page.
Closes#102450.
Closes#124257.
I've updated
_datetimemodule.c
and_pydatetime.py
such that calls to Python'sdatetime.time.fromisoformat
anddatetime.datetime.fromisoformat
both allow providing the24:00
ISO-8601 alternative to midnight, but the class constructors themselves do not (as perthis comment from @pganssle).Screenshots of the C code working:


I've also done the same tests for the
_pydatetime
module and everything appears to be working.Also updated the datetime tests accordingly, to ensure that
datetime.time.fromisoformat("24:00:00.000000")
is parsed asdatetime.time(0, 0, 0, 0)
etc. and the cases that should error (such asdatetime.time.fromisoformat("24:30")
) do indeed error.