Found by /verify-implementation plan-0ca7b7 (2026-09-26), measured @ 61bf20f with the built sharpyc; pre-existing at BASE acd1d40 unless noted.
datetime.datetime.strptime translates the python format into a .NET ParseExact format (Datetime.cs TranslateStrptimeFormat). Python (3.12) vs Sharpy:
| call |
python3 |
sharpy |
strptime("2021 003", "%Y %j") |
datetime(2021, 1, 3, 0, 0) |
FormatException |
strptime("2021-01-03 +0530", "%Y-%m-%d %z") |
aware, offset +05:30 |
FormatException |
strptime("2021-1-3", "%Y-%m-%d") |
datetime(2021, 1, 3, 0, 0) |
FormatException |
strptime("jan 3 2021", "%b %d %Y") |
datetime(2021, 1, 3, 0, 0) |
FormatException |
strptime("2021-01-03 1pm", "%Y-%m-%d %I%p") |
datetime(2021, 1, 3, 13, 0) |
FormatException |
strptime("x", "%Y") inside except ValueError |
ValueError: time data 'x' does not match format '%Y' |
uncaught System.FormatException (unhandled exception) |
The last row is the worst one: an expected failure isn't catchable by the python spelling. Class contract: strptime parses by python's directive grammar, the same way strftime now does (0eca2b3's Strftime.cs is the formatter twin), and a mismatch raises ValueError with python's message. Sibling of #2019.
Found by /verify-implementation plan-0ca7b7 (2026-09-26), measured @ 61bf20f with the built sharpyc; pre-existing at BASE acd1d40 unless noted.
datetime.datetime.strptimetranslates the python format into a .NETParseExactformat (Datetime.csTranslateStrptimeFormat). Python (3.12) vs Sharpy:strptime("2021 003", "%Y %j")datetime(2021, 1, 3, 0, 0)strptime("2021-01-03 +0530", "%Y-%m-%d %z")strptime("2021-1-3", "%Y-%m-%d")datetime(2021, 1, 3, 0, 0)strptime("jan 3 2021", "%b %d %Y")datetime(2021, 1, 3, 0, 0)strptime("2021-01-03 1pm", "%Y-%m-%d %I%p")datetime(2021, 1, 3, 13, 0)strptime("x", "%Y")insideexcept ValueErrorValueError: time data 'x' does not match format '%Y'System.FormatException(unhandled exception)The last row is the worst one: an expected failure isn't catchable by the python spelling. Class contract: strptime parses by python's directive grammar, the same way strftime now does (0eca2b3's
Strftime.csis the formatter twin), and a mismatch raises ValueError with python's message. Sibling of #2019.