[Python-ideas] Repr of lambda

Nick Coghlan ncoghlan at gmail.com
Sat Dec 23 20:18:08 EST 2017


On 22 Dec. 2017 12:32 pm, "Chris Angelico" <rosuav at gmail.com> wrote:

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).


Having the repr report the defining module name & line number in addition
to the object ID could be a low cost way of making the definition easier to
find without adding any overhead in the common case.

Cheers,
Nick.



ChrisA
_______________________________________________
Python-ideas mailing list
Python-ideas at python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20171224/c3df13d3/attachment.html>


More information about the Python-ideas mailing list