[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Python-Dev] PEP czar for PEP 3144?

On 3/19/2012 6:04 PM, Guido van Rossum wrote:
> On Mon, Mar 19, 2012 at 2:58 PM, Peter Moody<pmoody at google.com>  wrote:
>> On Mon, Mar 19, 2012 at 12:55 PM, Guido van Rossum<guido at python.org>  wrote:
>>> On Mon, Mar 19, 2012 at 12:37 PM, Ethan Furman<ethan at stoneleaf.us>  wrote:
>>>> Nick Coghlan wrote:
>>>>> Collapsing the address list has to build the result list anyway to
>>>>> actually handle the deduplication part of its job, so returning a
>>>>> concrete list makes sense in that case.
>>>> Having only one function return a list instead of an iterator seems
>>>> questionable.
>>>> Depending on the code it could either keep track of what it has returned so
>>>> far in a set and avoid duplication that way; or, just return an
>>>> `iter(listobject)` instead of `listobject`.
>>> I know I'm lacking context, but is the list ever expected to be huge?
>>> If not, what's wrong with always returning a list?
>> It's possible to return massive lists, (eg, returning the 4+ billion
>> /128 subnets in /96 or something even larger, but I don't think that's
>> very common). I've generally tried to avoid confusion by having 'iter'
>> in the iterating methods, but if more of the methods return iterators,
>> maybe I need to rethink that?
> I personally like having 'iter' in the name (e.g. iterkeys() -- note
> that we dropped this in Py3k because it's no longer an iterator, it's
> a dict view now. But I don't want to promote that style for ipaddr.py.

I am not sure which way you are pointing, but the general default in 3.x 
is to return iterators: range, zip, enumerate, map, filter, reversed, 
open (file objects), as well at the dict methods. I am quite happy to be 
rid of the 'iter' prefix on the latter. This is aside from itertools. 
The main exceptions I can think of are str.split and sorted. For sorted, 
a list *must* be constructed anyway, so might as well return it. This 
apparently matches the case under consideration. If name differentiation 
is wanted, call it xxxlist.

Terry Jan Reedy