

That kind of bioplastic tends not to biodegrade naturally, instead requiring a heated industrial composter with specially engineered enzymes added. If it’s disposed of properly, it’s great, otherwise it’s no better than traditional plastic but costs more. Also, not all bioplastics biodegrade at all as all the word means is that the source material is biomass rather than oil.
The interpreter can’t make the replacement until it’s about to execute the line as
__bool__
and__len__
are both (Python’s equivalent of) virtual functions, so it’s got to know the runtime type to know if the substitution is valid. Once it’s that late, it’ll often be faster to execute the requested function than work out if it could execute something faster instead. Even with type hints, it’s possible that a subclass with overridden methods could be passed in, so it’s not safe to do anything until the real runtime type is known.Once there’s a JIT involved, there’s an opportunity to detect the common types passed to a function and call specialised implementations, but I don’t think Python’s JIT is clever enough for this. LuaJIT definitely does this kind of optimisation, though.