[Python-Dev] weakref enhancements

Raymond Hettinger rhettinger at ewtllc.com
Thu Sep 28 21:02:20 CEST 2006


tomer filiba wrote:

> i'd like to suggest adding weak attributes and weak methods to the std 
> weakref
> module.

 . . .

>
> i think these two features are quite useful, and being part of the 
> stdlib, would
> provide programmers with easy-to-use solutions to object-aliveness issues.
>
> more info, examples, and suggested implementation:
> * http://sebulba.wikispaces.com/recipe+weakattr
> * http://sebulba.wikispaces.com/recipe+weakmethod 
> <http://sebulba.wikispaces.com/recipe+weakmethod>
>

I'm sceptical that these would find use in practice.  The cited links 
have only toy examples and as motivation reference Greg Ewing's posting 
saying only "I'm thinking it would be nice . . . This could probably be 
done fairly easily with a property descriptor." 

Also, I question the utility of maintaining a weakref to a method or 
attribute instead of holding one for the object or class.  As long as 
the enclosing object or class lives, so too will their methods and 
attributes.  So what is the point of a tighter weakref granualarity?

So, before being entertained for addition to the standard library, this 
idea should probably first be posted as an ASPN recipe, then we can see 
if any use cases emerge in actual practice.  Then we could look at 
sample code fragments to see if any real-world code is actually improved 
with the new toys.  My bet is that very few will emerge, that most would 
be better served by a simple decorator, and that an expanding weakref 
zoo will only making the module more difficult to learn.


Raymond








More information about the Python-Dev mailing list