File tree Expand file tree Collapse file tree 2 files changed +7
-6
lines changed Expand file tree Collapse file tree 2 files changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -251,8 +251,8 @@ def total_tokens(self) -> int | float:
251
251
def total_tokens (self , new_total_tokens : int | float ) -> None : # noqa: PYI041
252
252
if not isinstance (new_total_tokens , int ) and new_total_tokens != math .inf :
253
253
raise TypeError ("total_tokens must be an int or math.inf" )
254
- if new_total_tokens < 1 :
255
- raise ValueError ("total_tokens must be >= 1 " )
254
+ if new_total_tokens < 0 :
255
+ raise ValueError ("total_tokens must be >= 0 " )
256
256
self ._total_tokens = new_total_tokens
257
257
self ._wake_waiters ()
258
258
Original file line number Diff line number Diff line change @@ -49,9 +49,10 @@ async def child() -> None:
49
49
50
50
51
51
async def test_CapacityLimiter () -> None :
52
+ assert CapacityLimiter (0 ).total_tokens == 0
52
53
with pytest .raises (TypeError ):
53
54
CapacityLimiter (1.0 )
54
- with pytest .raises (ValueError , match = r"^total_tokens must be >= 1 $" ):
55
+ with pytest .raises (ValueError , match = r"^total_tokens must be >= 0 $" ):
55
56
CapacityLimiter (- 1 )
56
57
c = CapacityLimiter (2 )
57
58
repr (c ) # smoke test
@@ -139,10 +140,10 @@ async def test_CapacityLimiter_change_total_tokens() -> None:
139
140
with pytest .raises (TypeError ):
140
141
c .total_tokens = 1.0
141
142
142
- with pytest .raises (ValueError , match = r"^total_tokens must be >= 1 $" ):
143
- c .total_tokens = 0
143
+ with pytest .raises (ValueError , match = r"^total_tokens must be >= 0 $" ):
144
+ c .total_tokens = - 1
144
145
145
- with pytest .raises (ValueError , match = r"^total_tokens must be >= 1 $" ):
146
+ with pytest .raises (ValueError , match = r"^total_tokens must be >= 0 $" ):
146
147
c .total_tokens = - 10
147
148
148
149
assert c .total_tokens == 2
You can’t perform that action at this time.
0 commit comments