Fix #4157: handle error in case of unsupported format#4474
Fix #4157: handle error in case of unsupported format#4474itsankitkp wants to merge 47 commits intoRustPython:mainfrom
Conversation
Lib/test/test_time.py
Outdated
| # XXX this test case fails, this should have been handled in | ||
| # in in layers above fn strftime. | ||
| # self.assertRaises(ValueError, time.strftime, '%S\0', tt) | ||
|
|
||
| # check if unsupported arg in strftime returns arg itself | ||
| self.assertEqual(time.strftime("%4Y"), "%4Y") |
There was a problem hiding this comment.
No, CPython returns '2023'. But rust chrono doesn't support it yet
There was a problem hiding this comment.
We prefer to keep the tests in the Lib/test directory as close as possible to what's in CPython.
There was a problem hiding this comment.
Okay, should I keep it in extra_tests/snippets/stdlib_datetime.py ?
There was a problem hiding this comment.
If the "%S\0" case no longer panics, then you could change the decorator to this:
# TODO: RUSTPYTHON
@unittest.expectedFailure
def test_function():
# ...There was a problem hiding this comment.
If the
"%4Y"case no longer panics, then you could change the decorator to this:# TODO: RUSTPYTHON @unittest.expectedFailure def test_function(): # ...
I have done this, test ran fine.
vm/src/stdlib/time.rs
Outdated
|
|
||
| let mut formatted_time = String::new(); | ||
|
|
||
| /* | ||
| * chrono doesn't support all formats and it | ||
| * raised an error if unsupported format is supplied. | ||
| * If error happens, we set result as input arg | ||
| */ | ||
| let result = write!(&mut formatted_time, "{}", instant.format(format.as_str())); | ||
| match result { | ||
| Ok(r) => r, | ||
| Err(_) => formatted_time = format.to_string(), | ||
| }; |
There was a problem hiding this comment.
Does this work?
| let mut formatted_time = String::new(); | |
| /* | |
| * chrono doesn't support all formats and it | |
| * raised an error if unsupported format is supplied. | |
| * If error happens, we set result as input arg | |
| */ | |
| let result = write!(&mut formatted_time, "{}", instant.format(format.as_str())); | |
| match result { | |
| Ok(r) => r, | |
| Err(_) => formatted_time = format.to_string(), | |
| }; | |
| let formatted_time = String::try_from(instant.format(format.as_str())).unwrap_or(|| format.to_string()); |
There was a problem hiding this comment.
I am getting following error
the trait
std::convert::From<DelayedFormat<StrftimeItems<'_>>>is not implemented forstd::string::String
There was a problem hiding this comment.
But I do see what you are trying to do here. I will give another pass at this.
There was a problem hiding this comment.
I have refactored code, it looks lot better now
|
It's fine to have that |
Okay, I tried that but there is an issue
|
0cf0b04 to
d4c2fd3
Compare
I have fixed this for now by using unsupported format which returns same result in both python and rustpython. |
|
@itsankitkp it passes tests on ubuntu, but not on macos and windows. could you check it? |
fd2f370 to
052e984
Compare
Bumps [openssl-src](https://github.com/alexcrichton/openssl-src-rs) from 111.24.0+1.1.1s to 111.25.0+1.1.1t. - [Release notes](https://github.com/alexcrichton/openssl-src-rs/releases) - [Commits](https://github.com/alexcrichton/openssl-src-rs/commits) --- updated-dependencies: - dependency-name: openssl-src dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com>
Chrono panics in case of unsupported formats, this patch handles such cases and returns supplied format as a result.
be812d7 to
d4a6d39
Compare
|
rebase seems messed up. could you try: when upstream is |
This branch was messed up, I have created fresh PR with same changes with history fixed. |
|
Closing as I have opened other PR: #4530 with fixed git history |
Chrono panics in case of unsupported formats, this patch handles such cases and returns supplied format as a result.