The class is not documented to support __len__() or __bool__(), so this is not a bug. There is an empty() method provided for the purposes of testing whether a queue is empty or not. Likewise, there is a qsize() method for determining the current size.
Note, these methods have a built in race condition -- the information may be out of date by the time it is used. In general, an EAFP approach is preferred for reliable behavior (i.e. call get() in a try/except to see whether an Empty exception is raised).
FWIW, this module's API was designed by Guido a long time ago. Presumably, he had his reasons for choosing empty(), full(), and qsize() over the __len__() method. Once the API has been published and then become widely used, the time for debating his API decisions is over and we work with it as published. |