[Python-Dev] Retrieve an arbitrary element from a set withoutremoving it

Benjamin Peterson benjamin at python.org
Sat Oct 31 02:38:17 CET 2009


2009/10/30 Steven D'Aprano <steve at pearwood.info>:
> On Sat, 31 Oct 2009 07:27:22 am A.M. Kuchling wrote:
>> On Fri, Oct 30, 2009 at 09:37:36PM +0100, Georg Brandl wrote:
>> > I don't like this.  It gives a set object a hidden state, something
>> > that AFAICS no other builtin has.
>
> All objects have a reference count field which is hidden from Python
> code. The C API for objects has a flags field which specifies whether
> objects are read-only or read/write from Python code.
>
> As of Python 2.6, type objects have an internal method cache. C code can
> clear it with PyType_ClearCache(), Python codes can't even see it.
>
> Lists and dicts pre-allocate extra space, and record hidden state of how
> much of the space is actually in use. Sets may do the same. File
> objects may use internal buffers, with all the state that implies.

Those are all examples of states which are implementation details. The
proposed get() semantics would require that allow implementations keep
this state around.



-- 
Regards,
Benjamin


More information about the Python-Dev mailing list