Repository navigation
Conversation
…ormat() time.fromisoformat() and datetime.fromisoformat() read digits after the seconds of a basic-format time as a fractional second even without a decimal mark, so "12304512" was accepted by the C implementation but rejected by the pure-Python one.
Author
|
Closing as a duplicate of #155177, which makes the same change. Sorry for the noise, I missed it when searching. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
In
parse_hh_mm_ss_ff()a basic-format time (no:separators) steps back one character after each component so the next one can be parsed. After the seconds the loop then ends and the fractional part is parsed from whatever character comes next, without checking for a.or,. Sotime.fromisoformat("12304512")returned12:30:45.12in the C implementation, while_pydatetimeraisesValueError, as the C parser itself does for"12:30:4512".The fix returns the existing "malformed microsecond separator" error (
-4) when the character after the seconds is not a decimal mark and there is no separator.test_fromisoformat_fails(time) andtest_fromisoformat_fails_datetimehave new cases. They run for both implementations, and fail without the change for the C one (9 subtests across the_Fastclasses).Checked on a build of
main:test_datetime,test_time,test_strptime,test_calendar,test_zoneinfo,test_emailandtest_jsonpass. I did not run a refleak build, since the change only adds an early error return before any allocation.This is similar to gh-158501, which made the C parser reject stray text before an offset.
This was found by comparing the C
datetimewith_pydatetimeusing Hypothesis. The change was prepared with the help of an AI coding assistant (Devin CLI).