diff options
author | Jay <74105438+weijay0804@users.noreply.github.com> | 2023-06-13 04:29:02 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-12 20:29:02 +0000 |
commit | f0fb782ddb7208a59cfc38ec4bcbd8d1a81f8a58 (patch) | |
tree | f911c2581dd32e2631bd4a748823e185564e9779 /Lib/asyncio/tasks.py | |
parent | 9544948e7e2f288513137a62308e875dac086a18 (diff) | |
download | cpython-f0fb782ddb7208a59cfc38ec4bcbd8d1a81f8a58.tar.gz cpython-f0fb782ddb7208a59cfc38ec4bcbd8d1a81f8a58.zip |
gh-105331: Change `asyncio.sleep` to raise ``ValueError` for nan (#105641)
Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>
Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Diffstat (limited to 'Lib/asyncio/tasks.py')
-rw-r--r-- | Lib/asyncio/tasks.py | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/Lib/asyncio/tasks.py b/Lib/asyncio/tasks.py index 8d5bde09ea9..4250bb07538 100644 --- a/Lib/asyncio/tasks.py +++ b/Lib/asyncio/tasks.py @@ -15,6 +15,7 @@ import contextvars import functools import inspect import itertools +import math import types import warnings import weakref @@ -646,6 +647,9 @@ async def sleep(delay, result=None): await __sleep0() return result + if math.isnan(delay): + raise ValueError("Invalid delay: NaN (not a number)") + loop = events.get_running_loop() future = loop.create_future() h = loop.call_later(delay, |