On Tue, Jul 17, 2012 at 1:03 PM, Alex Gaynor <alex.gay...@gmail.com> wrote:
> I've updated the PEP to reflect the discussion. There are two major changes:
>
> 1) NotImplemented may be used by __length_hint__ to indicate that there is no
>    finite length hint available.

I've been thinking about this a bit more, and I think it does provide
good scope for eventually adding __length_hint__ to more iterators
(including map, filter and enumerate).

> 2) callers of operator.length_hint() must provide their own default value, 
> this
>    is also required by the current C _PyObject_LengthHint implementation.

And this makes it explicit that API users need to deal with the
AttributeError/NotImplemented case, whilst making it easy to do so.
Good call.

> There are no provisions for infinite iterators, that is not within the scope 
> of
> this proposal.

I'll repeat my observation that remaining silent on this point is
effectively identical to blessing the practice of raising an exception
in __length_hint__ to force fast failure of attempts to convert an
infinite iterator to a concrete container. Rather than leaving people
to figure this out on their own, we may as well make it official that
TypeError can be raised in __length_hint__ to block conversion to
concrete containers that use a preallocation strategy.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncogh...@gmail.com   |   Brisbane, Australia
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to