Relevant SO answer : https://stackoverflow.com/a/41861322/2610955
Ref : https://docs.python.org/3/reference/datamodel.html#object.__bool__
> If a class defines neither __len__() nor __bool__(), all its instances are considered true.
I don't know why it's not implemented and the SO answer comments has some discussion. Maybe this can be clarified in the doc.
➜ cpython git:(master) rlwrap ./python
Python 3.8.0a0 (heads/master:56868f9, Jul 21 2018, 14:28:31)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from queue import PriorityQueue
>>> len(PriorityQueue([1]))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: object of type 'PriorityQueue' has no len()
Thanks |