Re: [Python-ideas] Exploiting type-homogeneity in list.sort() (again!)

2017-03-08 Thread Chris Barker
On Wed, Mar 8, 2017 at 2:58 PM, Elliot Gorokhovsky < elliot.gorokhov...@gmail.com> wrote: > > The whole point of my patch is that we do O(nlogn) compares, but only have > O(n) elements, so it's much cheaper to do all the type checks in advance, > > I mean, practically speaking, the advance

Re: [Python-ideas] dict(default=int)

2017-03-08 Thread Dan Sommers
On Thu, 09 Mar 2017 09:43:48 +1100, Chris Angelico wrote: > On Thu, Mar 9, 2017 at 9:39 AM, Brice PARENT wrote: >> But a possible workaround, is if we used the first positional >> argument of dict() as the default value [...] > ... Granted, there aren't going to be very many objects that are

Re: [Python-ideas] Exploiting type-homogeneity in list.sort() (again!)

2017-03-08 Thread Elliot Gorokhovsky
On Wed, Mar 8, 2017 at 2:14 PM Barry wrote: > Can you assume that list of of type(list[0]) and use that type's optimised > sort? > But in the optimised sort code check that the types are as required. > If you hit an element that is not of the required type then fall back

Re: [Python-ideas] dict(default=int)

2017-03-08 Thread Eric V. Smith
On 3/8/2017 5:43 PM, Chris Angelico wrote: On Thu, Mar 9, 2017 at 9:39 AM, Brice PARENT wrote: But a possible workaround, is if we used the first positional argument of dict() as the default value. As right now it doesn't accept positional arguments (or at least if they are

Re: [Python-ideas] dict(default=int)

2017-03-08 Thread Chris Angelico
On Thu, Mar 9, 2017 at 9:39 AM, Brice PARENT wrote: > But a possible workaround, is if we used the first positional argument of > dict() as the default value. As right now it doesn't accept positional > arguments (or at least if they are not iterable, which complicates a bit

Re: [Python-ideas] dict(default=int)

2017-03-08 Thread Chris Angelico
On Thu, Mar 9, 2017 at 9:23 AM, Brice PARENT wrote: > Would those 2 dicts be equal ? > d1 = dict(default=5) > d2 = {'default': 5} Easy to find out: >>> d1 = dict(default=5) >>> d2 = {'default': 5} >>> d1 == d2 True ChrisA ___

Re: [Python-ideas] dict(default=int)

2017-03-08 Thread Mahmoud Hashemi
That's already valid dict syntax. >>> dict(default=int) {'default': } Generally that in itself makes this a no go. Mahmoud On Wed, Mar 8, 2017 at 2:09 PM, Steven Piantadosi wrote: > Hi All, > > I find importing defaultdict from collections to be clunky and it seems >

Re: [Python-ideas] Exploiting type-homogeneity in list.sort() (again!)

2017-03-08 Thread Erik
On 08/03/17 11:07, Steven D'Aprano wrote: I mentioned earlier that I have code which has to track the type of list items, and swaps to a different algorithm when the types are not all the same. Hmmm. Yes, I guess if the expensive version requires a lot of isinstance() messing or similar for

Re: [Python-ideas] Proposal: making __str__ count in time's class

2017-03-08 Thread Ethan Furman
On 03/08/2017 08:01 AM, Francesco Franchina wrote: Before expressing my thought and proposal, I want to make sure we all agree on a simple and clear fact: the __str__ magic method is used to give a literal and human-readable representation to the object (unlike __repr__). If __str__ has not

Re: [Python-ideas] Proposal: making __str__ count in time's class

2017-03-08 Thread Barry Scott
> On 8 Mar 2017, at 16:01, Francesco Franchina wrote: > > Hello everyone, > > I'm shortly writing to you about a reflection I lately made upon the current > functioning of __str__ for the time's class. > > Before expressing my thought and proposal, I want to make sure we

[Python-ideas] Proposal: making __str__ count in time's class

2017-03-08 Thread Francesco Franchina
Hello everyone, I'm shortly writing to you about a reflection I lately made upon the current functioning of __str__ for the time's class. Before expressing my thought and proposal, I want to make sure we all agree on a simple and clear fact: the __str__ magic method is used to give a literal and

Re: [Python-ideas] Exploiting type-homogeneity in list.sort() (again!)

2017-03-08 Thread Steven D'Aprano
On Wed, Mar 08, 2017 at 01:20:19AM +, Erik wrote: > >Part of the complexity here is that I'd like this flag to be available > >to Python code, not just a hidden internal state of the list. > > Out of interest, for what purpose? Generally, I thought Python code > should not need to worry