Raymond Hettinger <raymond.hettin...@gmail.com> added the comment:

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.

----------
resolution:  -> rejected
stage:  -> resolved
status: open -> closed
type: behavior -> enhancement
versions: +Python 3.8 -Python 3.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue34180>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to