Fix time.strptime (#6208)

This commit is contained in:
Jeong, YunWon
2025-10-23 17:28:53 +09:00
committed by GitHub
parent 153d0eef51
commit 2463bdff0e
3 changed files with 10 additions and 17 deletions

View File

@@ -284,8 +284,6 @@ class TimeTestCase(unittest.TestCase):
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:

View File

@@ -123,8 +123,6 @@ class AbstractTestsWithSourceFile:
# 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 @@ class AbstractTestsWithSourceFile:
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 @@ class AbstractTestZip64InSmallFiles:
# 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)

View File

@@ -364,15 +364,16 @@ mod decl {
}
#[pyfunction]
fn strptime(
string: PyStrRef,
format: OptionalArg<PyStrRef>,
vm: &VirtualMachine,
) -> PyResult<PyStructTime> {
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<PyStrRef>, 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(