Si consideri il seguente codice:weakref e __slots__
from weakref import ref
class Klass(object):
# __slots__ = ['foo']
def __init__(self):
self.foo = 'bar'
k = Klass()
r = ref(k)
funziona, ma quando ho rimuovere il commento dalla __slots__
rompe con TypeError: "cannot create weak reference to 'Klass' object"
sotto Python 2.6.
Per favore, qualcuno sa se questo è un limite intrinseco di Python e __slots__
o se si tratta di un bug? Come aggirarlo?