Define `trio.Event.__bool__()` to reduce bugs
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...
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.
Seems very useful for everyone who doesn't use mypy, including those on other typecheckers! (like me, for example 😅)
seems good, and should be a quick fix
What about normal(expected) behaviour + showing a warning (warnings.warn) on console additionally ? I saw this in the case of lxml (ElementTree if I remember correctly).
I think we should have a warning at first for deprecation reasons, but it should imitate the current behavior and return True.
But I suspect that having a proper traceback is nicer, plus warnings aren't harsh enough. And error->no error is trivial, no error->error requires a deprecation warning if we want to change this in the future.