| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
When parse_date or parse_time receives an input string whose numbers produce an out-of-range date or time (e.g. month 13, hour 25), the final datetime.date / datetime.time constructor raises a raw ValueError. Callers that catch ParseError (the documented error type for this module) never see the exception. Wrap both constructors in try/except and re-raise as ParseError with a message that includes the input string and the expected format pattern. Fixes python-babel#1178.
There was a problem hiding this comment.
This would need a test.
Also, I think it would be useful to raise from the ValueError, not None.
And... maybe the message needs some work? The exception is, after all, that the numbers we parsed out of the string don't represent a Gregorian date.
Sorry, something went wrong.
|
All three applied in 0e92abc:
|
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Problem
parse_date and parse_time both catch ParseError as their documented error type, but when the parsed numbers produce an out-of-range date or time value, the internal datetime.date / datetime.time constructor raises a raw ValueError that escapes to the caller uncaught.
Reported in #1178. Example:
Fix
Wrap the final datetime.date(year, month, day) call in parse_date and datetime.time(hour, minute, second) call in parse_time with try/except ValueError, re-raising as ParseError with an informative message that includes the input string and the expected format pattern.
All 2245 existing tests pass (2 xfailed unchanged).
Fixes #1178.