[Python-ideas] Fast sum() for non-numbers

Victor Stinner victor.stinner at gmail.com
Sat Jul 20 01:55:12 CEST 2013


2013/7/19 Sergey <sergemp at mail.ru>:
> Well, my current PEP-writing-skills are kind of zero, but the problem
> is that I don't know what to write there yet.

To write a PEP, I write 4 main sections:

- Abstract
- Rationale: why do you consider that something must be changed
- Proposal: describe your propositon
- Alternatives: list most alternatives proposed on python-ideas

You may list advantages and drawbacks of each alternative.

This is just a template to write a first draft ;-)

I read only a few emails of the sum() threads, but I remember the
following options:

- only sum numbers: reject all other types
- "if start is not None: x = start else x = first(items); for item in
items: x += item; return x" your proposal
- a new protocol (__concat__? I don't remember its name) with a
fallback on "x=start; for item in items: x += item" or to your
proposal
- implement __iadd__ for immutable types (tuple += tuple) or something like that
- etc.

> PEP probably implies
> that I want to change something, but my simplest patch [1] covers
> most of use cases and changes nothing, except performance, and
> should need no PEP.

You don't need an implementation to write a PEP. In your case, you
have an implementation. It's better to wait for a consensus on the PEP
before update the implementation to the last PEP, or you may waste
your time.

Victor


More information about the Python-ideas mailing list