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
I've now hit enough bugs where someone wrote if event: rather than if event.is_set(): that I think Event.__bool__() should raise an error of some kind, likely NotImplementedError("Trio events cannot be treated as bools; consider using 'event.is_set()'").
I could be argued into def __bool__(self): return self.is_set() but disprefer this - "there should be one obvious way to do it". Thoughts?
I don't think there's as urgent a need on other classes, but we could consider e.g. Condition and Semaphore too...
The text was updated successfully, but these errors were encountered:
Since trio.Event is marked as a final class, mypy (at least) supports --enable-error-code=truthy-bool that will warn on if event. (actually I'm not even sure if that requires being marked as final)
I'm not sure how useful something at runtime is compared to that though.
I've now hit enough bugs where someone wrote
if event:
rather thanif event.is_set():
that I thinkEvent.__bool__()
should raise an error of some kind, likelyNotImplementedError("Trio events cannot be treated as bools; consider using 'event.is_set()'")
.I could be argued into
def __bool__(self): return self.is_set()
but disprefer this - "there should be one obvious way to do it". Thoughts?I don't think there's as urgent a need on other classes, but we could consider e.g. Condition and Semaphore too...
The text was updated successfully, but these errors were encountered: