Repository navigation
WIP: bpo-1100942: Add datetime.time.strptime and datetime.date.strptime #5578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
ad5ffab
50606eb
ab5030f
07fb326
010ac8b
5b58fc1
8353a65
cff74a9
f92a799
4c4a7cc
b006172
ff7487f
a048f0e
9ac0af4
a952bb7
412aea2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3129,12 +3129,14 @@ def test_strftime(self): | |
| pass | ||
|
|
||
| def test_strptime_invalid(self): | ||
| tests = [('2004-12-01 13:02:47.197', | ||
| '%Y-%m-%d %H:%M:%S.%f'), | ||
| ('2004-12-01', '%Y-%m-%d'),] | ||
| tests = [ | ||
| ('2004-12-01 13:02:47.197', '%Y-%m-%d %H:%M:%S.%f'), | ||
| ('2004-12-01', '%Y-%m-%d'), | ||
| ] | ||
| for date_string, date_format in tests: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it would be good to use Also, per the other comment I guess you need to add something like
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you need two more test cases: ('1900-01-01 12:30', '%Y-%m-%d %H:%M'),
('12:30:15', ''),
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the test with For the other test, yep, there is an issue.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The fact that it doesn't raise an exception is an issue. I'm a bit surprised that it doesn't raise an exception on pure Python, that's a bug, because I'm pretty sure that:
|
||
| with self.assertRaises(ValueError): | ||
| time.strptime(date_string, date_format) | ||
| with self.subTest(date_string=date_string, date_format=date_format): | ||
| with self.assertRaises(ValueError): | ||
| time.strptime(date_string, date_format) | ||
|
|
||
| def test_strptime_valid(self): | ||
| string = '13:02:47.197' | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not move the msg string into the check function, and just pass the bit that varies ('date' or 'time') as an argument? It would make the code easier to read.
Looks like the check function either raises an exception or returns True. It would be clearer to not use an if statement here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
at the beginning, this PR was a submitted patch by other contributors, I just wanted to convert it to a PR. and now, I try to fix all the issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but for this point, the first step was the conversion of
_check_invalid_datetime_specsto C, and after start to improve the code with the other recommendations. (from @vstinner and @pganssle)