

18·
2 months agoThe fuel was going to end up burned anyway, so it’s only bad for the environment in that it’s incomplete combustion with lots of soot. It’s also preventing other fuel getting processed, so it could be a net benefit.
The fuel was going to end up burned anyway, so it’s only bad for the environment in that it’s incomplete combustion with lots of soot. It’s also preventing other fuel getting processed, so it could be a net benefit.
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.