This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: subtypable weak references
Type: enhancement Stage:
Components: Interpreter Core Versions:
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: BreamoreBoy, benjamin.peterson, david_abrahams, loewis
Priority: normal Keywords:

Created on 2002-02-09 00:50 by david_abrahams, last changed 2022-04-10 16:04 by admin. This issue is now closed.

Messages (6)
msg61078 - (view) Author: David Abrahams (david_abrahams) Date: 2002-02-09 00:50
I want to be able to create a subtype of weakref.

Motivation: I use a trick to non-intrusively keep one 
Python object (ward) alive as long as another one 
(custodian) is: I build a weak reference to the 
custodian whose kill function object holds a reference 
to the ward. I "leak" the weakref, but the function 
decrements its refcount so it will eventually die. 
This scheme costs an extra allocation for the function 
object, and because there is a function object at all, 
there's no opportunity to re-use the weakref (please 
document this part of the re-use behavior, BTW!)

I also want the re-use algorithm to check for object 
and type equality so that I can avoid creating 
multiple such references.
msg61079 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2002-02-17 00:06
Logged In: YES 
user_id=21627

This is what the WeakKeyDictionary is for: use the custodian
as the key, and the ward as the value.
msg61080 - (view) Author: David Abrahams (david_abrahams) Date: 2002-02-17 00:52
Logged In: YES 
user_id=52572

I wouldn't want to use WeakKeyDictionary directly for this, 
since I'm using it in a fairly time-critical place in C++ 
code. I could do the same thing with a proper subtype of 
dictionary using C++ code, and that's fine if you have a 
guarantee that a custodian has only one ward. Otherwise you 
need to use a collection of wards as the value, which again 
costs an extra allocation for the common case where a 
custodian really does have only one ward. Yes, it would be 
amortized over the number of wards for any custodian, but 
as I say the common case will have one ward per custodian. 
So I'd still really like to have weakref subclassing.
msg71508 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-08-20 02:52
Does anyone still care about this?
msg114176 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-08-17 21:43
Closing as nobody replied to msg71508.
msg114178 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2010-08-17 21:46
You can create weakref subclasses anyway now.
History
Date User Action Args
2022-04-10 16:04:58adminsetgithub: 36072
2010-08-17 21:46:43benjamin.petersonsetresolution: wont fix -> out of date
messages: + msg114178
2010-08-17 21:43:23BreamoreBoysetstatus: open -> closed

nosy: + BreamoreBoy
messages: + msg114176

resolution: wont fix
2008-08-20 02:52:34benjamin.petersonsetnosy: + benjamin.peterson
messages: + msg71508
2002-02-09 00:50:03david_abrahamscreate