-
-
Notifications
You must be signed in to change notification settings - Fork 30.7k
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
gh-105331: Fix asyncio.sleep() bug #105641
Conversation
Most changes to Python require a NEWS entry. Please add it using the blurb_it web app or the blurb command-line tool. |
Lib/asyncio/tasks.py
Outdated
@@ -950,21 +950,21 @@ def callback(): | |||
def create_eager_task_factory(custom_task_constructor): | |||
"""Create a function suitable for use as a task factory on an event-loop. | |||
|
|||
Example usage: | |||
Example usage: |
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.
Please fix the indentation change you (accidentally?) applied to much of this docstring. (Maybe your editor inserted tabs instead of spaces?)
Lib/asyncio/tasks.py
Outdated
@@ -642,6 +642,12 @@ def __sleep0(): | |||
|
|||
async def sleep(delay, result=None): | |||
"""Coroutine that completes after a given time (in seconds).""" | |||
|
|||
# check delay value is not nan | |||
import math |
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.
Just move this import to the toplevel, sorted between the rest of the imports.
Lib/asyncio/tasks.py
Outdated
# check delay value is not nan | ||
import math | ||
if math.isnan(delay): | ||
raise ValueError("Invalid value NaN (not a number)") |
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.
Suggestion:
raise ValueError("Invalid value NaN (not a number)") | |
raise ValueError("Invalid delay: NaN (not a number)") |
@@ -0,0 +1 @@ | |||
fix asyncio.sleep(float('nan')) does not raise ValueErro problem |
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.
Please try harder here. The text requires proper punctuation, capitalization, markup, and it should describe the change in behavior rather than just stating "fix the problem".
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 |
b3eed28
to
408814d
Compare
c0fa428
to
9bd7ced
Compare
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.
You need to add a test for this and versionchanged for docs that nans are now not allowed.
Lib/asyncio/tasks.py
Outdated
@@ -642,6 +643,11 @@ def __sleep0(): | |||
|
|||
async def sleep(delay, result=None): | |||
"""Coroutine that completes after a given time (in seconds).""" | |||
|
|||
# check delay value is not nan | |||
if math.isnan(delay): |
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.
Move this check after delay <= 0
check to not slow down the common case of sleep(0)
.
Misc/NEWS.d/next/Core and Builtins/2023-06-11-09-14-30.gh-issue-105331.nlZvoW.rst
Outdated
Show resolved
Hide resolved
…e-105331.nlZvoW.rst I think this way is more clearer. Thank you! Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>
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.
@kumaraditya303 Do you agree?
I pushed some minor tweaks, now LGTM. |
* main: pythongh-105540: Fix code generator tests (python#105707) pythongh-105375: Explicitly initialise all {Pickler,Unpickler}Object fields (python#105686) pythongh-105331: Change `asyncio.sleep` to raise ``ValueError` for nan (python#105641) Remove support for legacy bytecode instructions (python#105705)
Issue: gh-105331:
fix asyncio.sleep(float('nan')) does not raise ValueError