[Python-3000] ABC PEP -- dropping set.clear (original) (raw)

Guido van Rossum guido at python.org
Thu Apr 26 02:39:38 CEST 2007


On 4/25/07, Jim Jewett <jimjjewett at gmail.com> wrote:

On 4/25/07, guido.van.rossum <python-checkins at python.org> wrote: > + implementation.) Open issues: Forcing every mutable set > + to implement this may be a pain for such a fairly > + non-essential method. Perhaps just drop it?

There are also comments worrying that an abstract implementation would be horribly slow -- but so what?

True. In the discussion of hash returning 0 by default I even mention that I'd rather be slow and correct than fast and wrong. :-)

Alex Martelli posted some stats (for dicts, I think) showing that (even today) clear was slower than just creating a new object.

:)

It still makes sense if you care about the "is" relation

Since you are keeping "pop", the abstract implementation can at least approximate iteration. def clear(self): while self.pop(): pass

That would have to be

def clear(self): while True: try: self.pop() except KeyError: break

But yeah, I'll do this. Thanks for the reality check!

-- --Guido van Rossum (home page: http://www.python.org/~guido/)



More information about the Python-3000 mailing list