Making the case for "typed" lists/iterators in python

Terry Reedy tjreedy at udel.edu
Fri Dec 16 17:21:14 EST 2011


On 12/16/2011 1:05 PM, Roy Smith wrote:

> I'm working with now is functions that end in:
>
>     return [Foo(x) for x in bunch_of_x_thingies]
>
> When something goes amiss and I want to debug the problem, I often
> transform that into:
>
>      temp = [Foo(x) for x in bunch_of_x_thingies]
>      logger.debug(temp)
>      return temp
>
> It would be convenient to be able to get at and log the intermediate
> value without having to pull it out to an explicit temporary.

Decorate the function with @logreturn and you do not have to touch the 
function code. If the logging module does not now have such a decorator 
predefined (I simply do not know), perhaps it should.

-- 
Terry Jan Reedy




More information about the Python-list mailing list