-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Closed
Labels
Description
Bug report
time.sleep(float('nan')) raises ValueError, but asyncio.sleep(float('nan')) is valid and sleeps for 0. This seems bad, and asyncio.sleep should probably also raise ValueError.
import asyncio
import time
try:
time.sleep(float('nan'))
except ValueError:
print("time.sleep raised ValueError")
async def foo() -> None:
await asyncio.sleep(float('nan'))
print("asyncio.sleep does not raise any error")
asyncio.run(foo())$ python foo.py
time.sleep raised ValueError
asyncio.sleep does not raise any errortime.sleep and asyncio.sleep do differ in behaviour when it comes to negative numbers and changing that behaviour was considered a breaking change without strong reason: #83879
nan 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
- CPython versions tested on: 3.8 to 3.11
- Operating system and architecture:
Linux 6.3.4-arch1-1
Linked PRs
Metadata
Metadata
Assignees
Labels
Projects
Status
Done