Skip to content

Commit 4e54bd9

Browse files
committed
Separate handling of Unicode and other errors
In the initial implementation, errors other than encoding errors would both raise an error indicating an invalid format, which would not be true for errors like MemoryError.
1 parent eb8e176 commit 4e54bd9

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Modules/_datetimemodule.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4911,7 +4911,12 @@ datetime_fromisoformat(PyObject* cls, PyObject *dtstr) {
49114911
const char * dt_ptr = PyUnicode_AsUTF8AndSize(dtstr_clean, &len);
49124912

49134913
if (dt_ptr == NULL) {
4914-
goto invalid_string_error;
4914+
if (PyErr_ExceptionMatches(PyExc_UnicodeEncodeError)) {
4915+
// Encoding errors are invalid string errors at this point
4916+
goto invalid_string_error;
4917+
} else {
4918+
goto error;
4919+
}
49154920
}
49164921

49174922
const char *p = dt_ptr;

0 commit comments

Comments
 (0)