Issue1200

classification
Title: make __weakref__ work more similar to CPython
Type: Severity: minor
Components: Core Versions: 2.5b0
Milestone:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: pjenvey Nosy List: doublep, pjenvey
Priority: high Keywords:

Created on 2008-12-10.17:24:42 by doublep, last changed 2009-04-10.03:32:53 by pjenvey.

Messages
msg3907 (view) Author: (doublep) Date: 2008-12-10.17:24:42
I know that Java weak reference are implemented differently, e.g. all
objects are inherently weak-referencable and __weakref__ slot is
meaningless.  Still, Jython could add special handling for the slot to
simplify things for code that blindly (not checking exact
implementation) uses it.

E.g.:

class X (object):
    __slots__ = ('__weakref__')

x = X ()
x.__weakref__ = 1

This code fails in CPython but works fine in Jython.  However, it wastes
one slot, making each object unnecessarily larger (I admit I don't
really know how Jython works, but that's what I guess it results in). 
Also, it seems Jython is capable of not creating duplicate weakref object:

>>> a = object ()
>>> b = weakref.ref (a)
>>> c = weakref.ref (a)
>>> b, c, b is c
(<weakref at 1; to 'object' at 2>, <weakref at 1; to 'object' at 2>, True)

so x.__weakref__ (descriptor getter) could be implemented as in CPython.

I'm not proposing to artificially limit set of weak-referencable types
--- I'm just asking to make __weakref__ slot "just work as intended"
without caring whether it is CPython or Jython.
msg3910 (view) Author: Philip Jenvey (pjenvey) Date: 2008-12-10.23:03:56
I've been intending to do this for 2.5, thanks for the reminder
msg4499 (view) Author: Philip Jenvey (pjenvey) Date: 2009-04-10.03:32:52
fixed in r6198, thanks
History
Date User Action Args
2009-04-10 03:32:53pjenveysetstatus: open -> closed
resolution: accepted -> fixed
messages: + msg4499
2009-03-14 02:43:08fwierzbickisetpriority: high
2008-12-10 23:03:56pjenveysetassignee: pjenvey
resolution: accepted
messages: + msg3910
nosy: + pjenvey
2008-12-10 17:24:42doublepcreate