1+ import math
12from contextlib import contextmanager
23
34import trio
@@ -10,7 +11,12 @@ def move_on_at(deadline):
1011 Args:
1112 deadline (float): The deadline.
1213
14+ Raises:
15+ ValueError: if deadline is NaN.
16+
1317 """
18+ if math .isnan (deadline ):
19+ raise ValueError ("deadline must not be NaN" )
1420 return trio .CancelScope (deadline = deadline )
1521
1622
@@ -22,10 +28,9 @@ def move_on_after(seconds):
2228 seconds (float): The timeout.
2329
2430 Raises:
25- ValueError: if timeout is less than zero.
31+ ValueError: if timeout is less than zero or NaN .
2632
2733 """
28-
2934 if seconds < 0 :
3035 raise ValueError ("timeout must be non-negative" )
3136 return move_on_at (trio .current_time () + seconds )
@@ -52,6 +57,9 @@ async def sleep_until(deadline):
5257 the past, in which case this function executes a checkpoint but
5358 does not block.
5459
60+ Raises:
61+ ValueError: if deadline is NaN.
62+
5563 """
5664 with move_on_at (deadline ):
5765 await sleep_forever ()
@@ -65,7 +73,7 @@ async def sleep(seconds):
6573 insert a checkpoint without actually blocking.
6674
6775 Raises:
68- ValueError: if *seconds* is negative.
76+ ValueError: if *seconds* is negative or NaN .
6977
7078 """
7179 if seconds < 0 :
@@ -96,9 +104,13 @@ def fail_at(deadline):
96104 :func:`fail_at`, then it's caught and :exc:`TooSlowError` is raised in its
97105 place.
98106
107+ Args:
108+ deadline (float): The deadline.
109+
99110 Raises:
100111 TooSlowError: if a :exc:`Cancelled` exception is raised in this scope
101112 and caught by the context manager.
113+ ValueError: if deadline is NaN.
102114
103115 """
104116
@@ -119,10 +131,13 @@ def fail_after(seconds):
119131 it's caught and discarded. When it reaches :func:`fail_after`, then it's
120132 caught and :exc:`TooSlowError` is raised in its place.
121133
134+ Args:
135+ seconds (float): The timeout.
136+
122137 Raises:
123138 TooSlowError: if a :exc:`Cancelled` exception is raised in this scope
124139 and caught by the context manager.
125- ValueError: if *seconds* is less than zero.
140+ ValueError: if *seconds* is less than zero or NaN .
126141
127142 """
128143 if seconds < 0 :
0 commit comments