-
-
Notifications
You must be signed in to change notification settings - Fork 32k
time.sleep error message misleading #81267
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
Comments
Using python3.6 and calling |
The doc (3.7) says that the argument "may be a floating point number to indicate a more precise sleep time." |
I think it's reasonable to change the TypeError to say integer or float. That's what _PyTime_FromObject is looking for. |
While not exactly the same, bpo-35707 is also about time.sleep and floats. |
From looking at the code for this (note I am not a C programmer so may have gotten this wrong) _PyTime_FromObject first checks if the object is a float using PyFloat_Check(obj) this is evident as passing nan to time.sleep raises a ValueError with the message "Invalid value NaN (not a number)". However if the object is not a float it next assumes the only valid value to be an integer, this logic appears fine to me. The problem however is if the object is not an integer the code raises the error with the message that an integer is required, it is unaware that a before this branch of the code executes a float would have been an accepted value. In python I imagine the fix for this would be along the lines try: |
I just create a PR for it. |
Uh oh!
There was an error while loading. Please reload this page.
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
Linked PRs
time.sleep
error message #131055The text was updated successfully, but these errors were encountered: