Betrachten Sie den folgenden Code ein:WeakRef und __slots__
from weakref import ref
class Klass(object):
# __slots__ = ['foo']
def __init__(self):
self.foo = 'bar'
k = Klass()
r = ref(k)
es funktioniert, aber wenn ich die __slots__
Kommentar- bricht es mit TypeError: "cannot create weak reference to 'Klass' object"
unter Python 2.6.
Bitte weiß jemand, ob dies eine inhärente Einschränkung von Python und __slots__
oder wenn es ein Fehler ist? Wie man es umgeht?