-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
bpo-26669: Fix nan arg value error in pytime.c #3085
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
Conversation
|
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept your contribution by verifying you have signed the PSF contributor agreement (CLA). Unfortunately we couldn't find an account corresponding to your GitHub username on bugs.python.org (b.p.o) to verify you have signed the CLA (this might be simply due to a missing "GitHub Name" entry in your b.p.o account settings). This is necessary for legal reasons before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. Thanks again to your contribution and we look forward to looking at it! |
Python/pytime.c
Outdated
|
|
||
| d = PyFloat_AsDouble(obj); | ||
| if (isnan(d)) { | ||
| PyErr_SetString(PyExc_ValueError, "Invalid Value"); |
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.
Might be helpful for the error message specifically to mention that the value is NaN.
|
@Haypo, do you have any comments about this? |
|
|
||
| # Issue #26669: check for localtime() failure | ||
| self.assertRaises(ValueError, time.localtime, float("nan")) | ||
| self.assertRaises(ValueError, time.ctime, float("nan")) |
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.
Ok for "functional" tests", but I also would like to see unit tests on the following _testcapi functions:
- pytime_object_to_time_t
- pytime_object_to_timeval
- pytime_object_to_timespec
- PyTime_FromSeconds
- PyTime_FromSecondsObject
- PyTime_AsSecondsDouble
See CPyTimeTestCase in test_time.py.
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase And if you don't make the requested changes, you will be put in the comfy chair! |
|
Hmm... Did @warsaw hack the bot? |
|
@Sn0wLe0pard: Would you mind to add requested unit tests? Otherwise, I might try to modify your PR to add them myself? |
|
@Haypo I'll add test case as soon as possible. |
|
@Haypo I'm really sorry for the delay in writing the code. SummarySystem: Ubuntu 16.04 x86
ResultI tested the following code in # test nan
for time_rnd, _ in ROUNDING_MODES:
with self.assertRaises(ValueError):
pytime_converter(float('nan'), time_rnd)Here are the results: ...so I tested one by one.
And In case I add but i think If the result is the same as expected, I will replace the passed test code with the changed |
|
pytime_object_to_timeval also has same error on macOS sierra |
|
Oh... in case NaN numerator is zero. I add some code for numerator zero. then it pass all test cases. |
|
Ok, it now LGTM! |
|
🐍🍒⛏🤖 Thanks @Sn0wLe0pard for the PR, and @Haypo for merging it 🌮🎉.I'm working now to backport this PR to: 3.6. |
* Fix pythonGH-26669 * Modify NaN check function and error message * Fix pytime.c when arg is nan * fix whitespace (cherry picked from commit 829dacc)
|
GH-3467 is a backport of this pull request to the 3.6 branch. |
Previously, it did not show error message in arm system
https://bugs.python.org/issue26669