From 34c56f87a9eb32ae7a08719e6c00eecbb0a65e01 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Thu, 23 Oct 2025 16:35:53 +0900 Subject: [PATCH] Fix time.strptime --- Lib/test/test_time.py | 2 -- Lib/test/test_zipfile.py | 6 ------ vm/src/stdlib/time.rs | 19 ++++++++++--------- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/Lib/test/test_time.py b/Lib/test/test_time.py index 3886aae934..31a2a920d9 100644 --- a/Lib/test/test_time.py +++ b/Lib/test/test_time.py @@ -284,8 +284,6 @@ def test_strptime_bytes(self): self.assertRaises(TypeError, time.strptime, b'2009', "%Y") self.assertRaises(TypeError, time.strptime, '2009', b'%Y') - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_strptime_exception_context(self): # check that this doesn't chain exceptions needlessly (see #17572) with self.assertRaises(ValueError) as e: diff --git a/Lib/test/test_zipfile.py b/Lib/test/test_zipfile.py index 43178ca26b..0a50f03604 100644 --- a/Lib/test/test_zipfile.py +++ b/Lib/test/test_zipfile.py @@ -123,8 +123,6 @@ def zip_test(self, f, compression, compresslevel=None): # Check that testzip doesn't raise an exception zipfp.testzip() - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_basic(self): for f in get_files(self): self.zip_test(f, self.compression) @@ -394,8 +392,6 @@ def test_repr(self): self.assertIn('[closed]', repr(zipopen)) self.assertIn('[closed]', repr(zipfp)) - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_compresslevel_basic(self): for f in get_files(self): self.zip_test(f, self.compression, compresslevel=9) @@ -751,8 +747,6 @@ def zip_test(self, f, compression): # Check that testzip doesn't raise an exception zipfp.testzip() - # TODO: RUSTPYTHON - @unittest.expectedFailure def test_basic(self): for f in get_files(self): self.zip_test(f, self.compression) diff --git a/vm/src/stdlib/time.rs b/vm/src/stdlib/time.rs index 4ad29d0fe1..fb64e28b90 100644 --- a/vm/src/stdlib/time.rs +++ b/vm/src/stdlib/time.rs @@ -364,15 +364,16 @@ mod decl { } #[pyfunction] - fn strptime( - string: PyStrRef, - format: OptionalArg, - vm: &VirtualMachine, - ) -> PyResult { - let format = format.as_ref().map_or("%a %b %H:%M:%S %Y", |s| s.as_str()); - let instant = NaiveDateTime::parse_from_str(string.as_str(), format) - .map_err(|e| vm.new_value_error(format!("Parse error: {e:?}")))?; - Ok(PyStructTime::new(vm, instant, -1)) + fn strptime(string: PyStrRef, format: OptionalArg, vm: &VirtualMachine) -> PyResult { + // Call _strptime._strptime_time like CPython does + let strptime_module = vm.import("_strptime", 0)?; + let strptime_func = strptime_module.get_attr("_strptime_time", vm)?; + + // Call with positional arguments + match format.into_option() { + Some(fmt) => strptime_func.call((string, fmt), vm), + None => strptime_func.call((string,), vm), + } } #[cfg(not(any(