bool(obj) in Python has the following semantics:
1. if the object has __bool__() method, return its value
2. if the object has __len__() method, return its value
3. return True
So for objects in QGIS API that implement __len__() method, we were getting
unexpected behavior - for example, "if layer: ..." would evaluate as False
in case the layer was empty, while the usual expectation is that any reference
to an object that is not None should evaluate to True.