-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
asyncio.sleep(float('nan')) does not raise ValueError #105331
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
It is also different for negative values. For example: >>> import asyncio
>>> async def a():
... await asyncio.sleep(-1)
...
>>> asyncio.run(a()) and >>> import time
>>> time.sleep(-1)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: sleep length must be non-negative |
Yes, I wrote
|
I don't think we should change it at this point, I can accept a docs improvement for this but I'm -1 on changing the behavior. |
fwiw I'd expect it to follow whatever |
Hm, I expect at this point there is probably plenty of working code out there that passes a negative delay to I don't see how NaN could be the result of such a computation, so I agree NaN is a "weird" argument (and leads to undefined behavior). So I think I can only approve of the NaN check. |
…5641) Co-authored-by: Guido van Rossum <[email protected]> Co-authored-by: Kumar Aditya <[email protected]>
* 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)
Bug report
time.sleep(float('nan'))
raisesValueError
, butasyncio.sleep(float('nan'))
is valid and sleeps for 0. This seems bad, andasyncio.sleep
should probably also raiseValueError
.time.sleep
andasyncio.sleep
do differ in behaviour when it comes to negative numbers and changing that behaviour was considered a breaking change without strong reason: #83879nan
feels like it should very rare to be passed intentionally, but the potential gain might also be small enough that this isn't worth fixing.Related: python-trio/trio#2493
Your environment
Linux 6.3.4-arch1-1
Linked PRs
The text was updated successfully, but these errors were encountered: