Re: [Python-ideas] Repr of lambda
On Fri, Dec 22, 2017 at 9:43 AM, Chris Barkerwrote: > 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 ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
Re: [Python-ideas] Repr of lambda
On Thu, Dec 21, 2017 at 12:34 PM, Barrywrote: > > On 21 Dec 2017, at 06:57, Chris Barker 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(1)) In [15]: repr(arr) Out[15]: 'array([ 0,1,2, ..., 9997, 9998, ])' 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? -CHB -- Christopher Barker, Ph.D. Oceanographer Emergency Response Division NOAA/NOS/OR(206) 526-6959 voice 7600 Sand Point Way NE (206) 526-6329 fax Seattle, WA 98115 (206) 526-6317 main reception chris.bar...@noaa.gov ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
Re: [Python-ideas] Allow star unpacking within an slice expression
I didn't think of this when we were discussing 448. I ran into this today, so I agree with you that it would be nice to have this. Best, Neil On Monday, December 4, 2017 at 1:02:09 AM UTC-5, Eric Wieser wrote: > > Hi, > > I've been thinking about the * unpacking operator while writing some numpy > code. PEP 448 allows the following: > >values = 1, *some_tuple, 2 >object[(1, *some_tuple, 2)] > > It seems reasonable to me that it should be extended to allow > >item = object[1, *some_tuple, 2] >item = object[1, *some_tuple, :] > > Was this overlooked in the original proposal, or deliberately rejected? > > Eric > ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
Re: [Python-ideas] Repr of lambda
Could we call it "help"? Maybe add some beef to what's already there... >>> help(lambda x,y,*args: x) Help on function in module __main__: lambda x, y, *args On Thu, Dec 21, 2017 at 12:34 PM, Barrywrote: > > > > On 21 Dec 2017, at 06:57, Chris Barker wrote: > > > > in theory, the "goal" is for eval(repr(obj)) to return an equivelent > object > > Is that really was the goal of repr? If true then we would not need pickle. > > 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. > > Lamba seems to be in the complex end of things. > > 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. > > Maybe what you would like to have is an explain function that given any > object tells you alll about it. help function does some of this I guess. > > Barry > > ___ > Python-ideas mailing list > Python-ideas@python.org > https://mail.python.org/mailman/listinfo/python-ideas > Code of Conduct: http://python.org/psf/codeofconduct/ > ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
Re: [Python-ideas] Repr of lambda
> On 21 Dec 2017, at 06:57, Chris Barkerwrote: > > in theory, the "goal" is for eval(repr(obj)) to return an equivelent object Is that really was the goal of repr? If true then we would not need pickle. 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. Lamba seems to be in the complex end of things. 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. Maybe what you would like to have is an explain function that given any object tells you alll about it. help function does some of this I guess. Barry ___ Python-ideas mailing list Python-ideas@python.org https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/