Why doesn't an empty PriorityQueue evaluate to False
like other iterables in Python?
>>> from queue import PriorityQueue
>>> q1 = PriorityQueue()
>>> bool(q1)
True
>>> q1.qsize()
0
As you can see from the source code, the PriorityQueue
class doesn't implement __len__
or __bool__
, and the default is that if an object is present it's truthy:
If a class defines neither
__len__()
nor__bool__()
, all its instances are considered true.