Skip to content
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

Merged
merged 14 commits into from Jun 12, 2023
Merged

Conversation

weijay0804
Copy link
Contributor

Issue: gh-105331:
fix asyncio.sleep(float('nan')) does not raise ValueError

@bedevere-bot
Copy link

Most changes to Python require a NEWS entry.

Please add it using the blurb_it web app or the blurb command-line tool.

@@ -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:
Copy link
Member

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?)

@@ -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
Copy link
Member

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.

# check delay value is not nan
import math
if math.isnan(delay):
raise ValueError("Invalid value NaN (not a number)")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion:

Suggested change
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
Copy link
Member

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".

@bedevere-bot
Copy link

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 I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

Copy link
Contributor

@kumaraditya303 kumaraditya303 left a 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.

@@ -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):
Copy link
Contributor

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).

…e-105331.nlZvoW.rst


I think this way is more clearer.
Thank you!

Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>
Copy link
Member

@gvanrossum gvanrossum left a 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?

@kumaraditya303
Copy link
Contributor

Do you agree?

I pushed some minor tweaks, now LGTM.

@kumaraditya303 kumaraditya303 enabled auto-merge (squash) June 12, 2023 20:27
@kumaraditya303 kumaraditya303 merged commit f0fb782 into python:main Jun 12, 2023
14 of 17 checks passed
carljm added a commit to carljm/cpython that referenced this pull request Jun 12, 2023
* 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)
@weijay0804 weijay0804 deleted the fix-issue-105331 branch June 13, 2023 07:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants