[Python-checkins] peps: Updates to PEP-0424 following the discussion.

alex.gaynor python-checkins at python.org
Sun Jul 15 01:49:45 CEST 2012


http://hg.python.org/peps/rev/d4e77ba5329d
changeset:   4490:d4e77ba5329d
user:        Alex Gaynor <alex.gaynor at gmail.com>
date:        Sat Jul 14 16:49:42 2012 -0700
summary:
  Updates to PEP-0424 following the discussion.

files:
  pep-0424.txt |  23 +++++++----------------
  1 files changed, 7 insertions(+), 16 deletions(-)


diff --git a/pep-0424.txt b/pep-0424.txt
--- a/pep-0424.txt
+++ b/pep-0424.txt
@@ -14,8 +14,8 @@
 ========
 
 CPython currently defines an ``__length_hint__`` method on several types, such
-as various iterators. This method is then used by various other functions (such as
-``map``) to presize lists based on the estimated returned by
+as various iterators. This method is then used by various other functions (such
+as ``map``) to presize lists based on the estimated returned by
 ``__length_hint__``. Types can then define ``__length_hint__`` which are not
 sized, and thus should not define ``__len__``, but can estimate or compute a
 size (such as many iterators).
@@ -26,10 +26,11 @@
 This PEP proposes formally documenting ``__length_hint__`` for other
 interpreter and non-standard library Python to implement.
 
-``__length_hint__`` must return an integer, and is not required to be accurate.
-It may return a value that is either larger or smaller than the actual size of
-the container. It may raise a ``TypeError`` if a specific instance cannot have
-its length estimated. It may not return a negative value.
+``__length_hint__`` must return an integer (else a TypeError is raised), and is
+not required to be accurate. It may return a value that is either larger or
+smaller than the actual size ofthe container. It may raise a ``TypeError`` if a
+specific instance cannot have its length estimated. It may not return a
+negative value (else a ValueError is raised).
 
 Rationale
 =========
@@ -38,16 +39,6 @@
 observed to run some code faster than PyPy, purely because of this optimization
 being present.
 
-Open questions
-==============
-
-There are two open questions for this PEP:
-
-* Should ``list`` expose a kwarg in it's constructor for supplying a length
-  hint.
-* Should a function be added either to ``builtins`` or some other module which
-  calls ``__length_hint__``, like ``builtins.len`` calls ``__len__``.
-
 Copyright
 =========
 

-- 
Repository URL: http://hg.python.org/peps


More information about the Python-checkins mailing list