A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2012-July/120921.html below:

[Python-Dev] PEP 0424: A method for exposing a length hint

[Python-Dev] PEP 0424: A method for exposing a length hint [Python-Dev] PEP 0424: A method for exposing a length hintBenjamin Peterson benjamin at python.org
Sun Jul 15 01:18:38 CEST 2012
2012/7/14 Alex Gaynor <alex.gaynor at gmail.com>:
>
> Proposal
> ========
>
> 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.

And what happens if you return a negative value?

>
> Rationale
> =========
>
> Being able to pre-allocate lists based on the expected size, as estimated by
> ``__length_hint__``, can be a significant optimization. CPython has been
> 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__``.

Let's try to keep this as limited as possible for a public API.


-- 
Regards,
Benjamin
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4