[Python-ideas] Repr of lambda

Chris Angelico rosuav at gmail.com
Thu Dec 21 18:31:35 EST 2017


On Fri, Dec 22, 2017 at 9:43 AM, Chris Barker <chris.barker at noaa.gov> wrote:
> Every python object has an object identity, and the way to get it is with
> the id() function. The id is also part of the default object repr, but given
> that some, but only some objects have the id in their repr, it's probably
> better to use id() in you logs if you care.
>
> And in the case of lambda, wouldn't you rather see what the lambda actually
> WAS than what it's id is?
>
> Is there any downside other than backward compatibility concerns?

It's probably worth hanging onto the id, in case the same function
(from the same line of code) is used in multiple contexts. But IMO
having the text of the function would be very useful - as long as it
can be done without costing too much time or memory. So I'm +0.75 on
the idea, with the caveat that it'd have to be implemented and
performance-tested to make sure it doesn't kill the common case of a
lambda function being created, used, and then dropped (think of a sort
key function, for instance).

ChrisA


More information about the Python-ideas mailing list