weakref.proxy behaviour in python 3.0

Nicholas Cole nicholas.cole at gmail.com
Sat Aug 21 12:06:57 EDT 2010


On Sat, Aug 21, 2010 at 3:31 PM, Mark Dickinson <dickinsm at gmail.com> wrote:

[SNIP]

> So my guess is that the change was unintentional.
>
> It's probably worth a bug report.  Even if the behaviour isn't going
> to change in either 2.x or 3.x (and it probably isn't), it might be
> possible to clarify the docs.

Dear Mark,

I think the docs should be fixed: it would be good to have a list of
key examples where the behaviour is different.  Although the new
behaviour is better, it certainly tripped me up badly.

I'm happy to fill a report out, but since you seem to know much more
about the internals, I wonder if a bug report written by you would be
more useful!

Just in case it helps, one thing that does seem to be the case is that
two different proxy objects to the same real object get compared in
the same way on both versions.  So this code:

a = weakref.proxy(the_real_object)
b = weakref.proxy(the_real_object)

this_list = [ a, ]

l.remove(a) # Obviously works on both - just here for clarity.

l.remove(the_real_object) # Fails on python 2.6

l.remove(b) # gives an empty list on python 2.6 and python 3.


Very best wishes,

Nicholas



More information about the Python-list mailing list