from __future__ import * 25.2.2004

2004-02-25

The dict.popitem conspiracy

I was creating PyProtocols interfaces for dict-like objects today, and I got stuck trying to decide whether dict.popitem is worthy of including in the interface for a mutable mapping. I have never used it, and I couldn't remember ever seeing it in use, so I checked the standard library. Other than objects that expose the same interface as dict, it seems that popitem is used once and only once in the entire standard library:

def pop(self):
    """Remove and return an arbitrary set element."""
    return self._data.popitem()[0]

I guess it might be vestige from before Python had a decent iterator protocol (though Set doesn't have the excuse of being so old).. but it's pretty ridiculous that popitem is used more often to expose dict-like interfaces than it is used to actually do something.

posted at 15:54:24    #    comment []    trackback []
February
MoTuWeThFrSaSu
       1
2 3 4 5 6 7 8
9101112131415
16171819202122
23242526272829
Jan Mar

Bob's Rants

XML-Image Letterimage

© 2004, Bob Ippolito