Builtins.lazy for lazy arguments

I still don’t think that a global wrapper is required for this. Without modifying logger you can already do:

def logger_debug(a, *args):
   if debug > 0:
       print(a % args)
       
class LazyString:
    def __init__(self, callback):
        self.callback = callback
    def __str__(self):
        return str(self.callback())

logger_debug("%s happened", LazyString(lambda: "a problem"))
#a problem happened

If you would implement lazy, you still would need to modify logger.

1 Like