Skip to content

Define trio.Event.__bool__() to reduce bugs #3238

Open
@Zac-HD

Description

@Zac-HD

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...

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions