Consider the following code:
from weakref import ref
class Klass(object):
# __slots__ = ['foo']
def __init__(self):
self.foo = 'bar'
k = Klass()
r = ref(k)
it works but when I uncomment the __slots__
it breaks with TypeError: "cannot create weak reference to 'Klass' object"
under Python 2.6.
Please, does anyone know if this is an inherent limitation of Python and __slots__
or if it is a bug? How to work-around it?