I've got a condition like the following:
if limit > current and expensive_function() is not None:
logging.debug('Limit:%s Current:%s Expensive_Result:%s',
limit,
current,
expensive_function())
current += 1
I put expensive_function()
at the end of the conditional because it is expensive. How can I cache the value to not reiterate over it when logging?
I have considered breaking up the conditional into two, but I am worried it's making the code less readable:
if limit > current:
expensive_result = expensive_function()
if expensive_result is not None:
logging.debug('Limit:%s Current:%s Expensive_Result:%s',
limit,
current,
expensive_result)
current += 1