FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fix time.strptime by youknowone · Pull Request #6208 · RustPython/RustPython · GitHub

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rs  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 0 additions & 2 deletions Lib/test/test_time.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 0 additions & 6 deletions Lib/test/test_zipfile.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
19 changes: 10 additions & 9 deletions vm/src/stdlib/time.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading

Back | FazBrowse Home | New Git URL