You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Generally this is correct, but I had a use case where I wanted to disable the semaphore without restructuring my code, so I used float("inf") as the value to ensure that it never unlocks. This works perfectly fine, because the only operations that value needs to support are:
Adding 1
Subtracting 1
Comparing to 0
The infinity float value does all of these fine. So I therefore wonder if we should make this type be int | Literal[math.inf]? I agree that general floats are not a good idea because they will get below 0 without triggering the wait.
The text was updated successfully, but these errors were encountered:
I'm honestly wary to allow arbitrary floats here as using them could lead to bugs due to floating point math. I would suggest to use a big int instead, e.g. 2**64-1.
Currently we assume that the semaphore's value must be an integer:
typeshed/stdlib/asyncio/locks.pyi
Lines 88 to 93 in 1af9de6
Generally this is correct, but I had a use case where I wanted to disable the semaphore without restructuring my code, so I used
float("inf")
as the value to ensure that it never unlocks. This works perfectly fine, because the only operations thatvalue
needs to support are:The infinity float value does all of these fine. So I therefore wonder if we should make this type be
int | Literal[math.inf]
? I agree that general floats are not a good idea because they will get below 0 without triggering the wait.The text was updated successfully, but these errors were encountered: