[Python-ideas] Repr of lambda

Chris Barker chris.barker at noaa.gov
Thu Dec 21 17:43:14 EST 2017

On Thu, Dec 21, 2017 at 12:34 PM, Barry <barry at barrys-emacs.org> wrote:

> > On 21 Dec 2017, at 06:57, Chris Barker <chris.barker at noaa.gov> wrote:
> >
> > in theory, the "goal" is for eval(repr(obj)) to return an equivalent
> object
> Is that really was the goal of repr?

I think so -- see the current discussion about pprint and dict order....

> If true then we would not need pickle.

well, it only a goal, and it's not going to work for complex objects...

I have always assumed that repr of simple things aims to represent them
> in just the way you would write them in python code. Repr of complex things
> represents the obj as a useful summary.

pretty much, yes.

> Lamba seems to be in the complex end of things.

I think that's where the key disagreement comes in -- I think we'd al agree
that regular, def-defined functions are well in the complex end of things.

But lambda is limited to a single expression, so it can only get so complex
-- granted you could nest a lot of parentheses and function calls and have
a very complex expression, but the common use case is pretty compact.

Some reprs will truncate the result if the objec is huge -- numpy arrays
come to mind.

In [14]: arr = np.array(range(10000))

In [15]: repr(arr)
Out[15]: 'array([   0,    1,    2, ..., 9997, 9998, 9999])'

so if folks are worried that it could get too long, it could be limited.
Though I note that lists don;t seem to do anything like that -- try a
10,000 element list.

In debug logs I am often very interested in object identity and use the
> 0x123 as one way to know. Removing the unique id would be a regression
> in my eyes.

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?



Christopher Barker, Ph.D.

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20171221/4a0a5cde/attachment-0001.html>

More information about the Python-ideas mailing list