[Python-Dev] Patch for Weak References for Functions

Phil Thompson phil@river-bank.demon.co.uk
Sat, 10 Mar 2001 11:06:13 +0000


Paul Prescod wrote:
> 
> Phil Thompson wrote:
> >
> >...
> >
> > To be honest, I don't see why weak references have been implemented as a
> > bolt-on module that only supports one particular object type. The thing
> > I most like about the Python implementation is how consistent it is.
> > Weak references should be implemented for every object type - even for
> > None - you never know when it might come in useful.
> 
> Weak references add a pointer to each object. This could add up for
> (e.g.) integers. The idea is that you only pay the cost of weak
> references for objects that you would actually create weak references
> to.

Yes I know, and I'm suggesting that people will always find extra uses
for things which the original designers hadn't thought of. Better to be
consistent (and allow weak references to anything) than try and
anticipate (wrongly) how people might want to use it in the future -
although I appreciate that the implementation cost might be too high.
Perhaps the question should be "what types make no sense with weak
references" and exclude them rather than "what types might be able to
use weak references" and include them.

Having said that, my only immediate requirement is to allow weak
refences to functions, and I'd be happy if only that was implemented.

Phil