-
-
Notifications
You must be signed in to change notification settings - Fork 424
slots=True classes are not weak-referenceable #174
Copy link
Copy link
Closed
Description
This code:
import weakref
import attr
@attr.s(slots=True)
class Foo(object):
x = attr.ib()
weakref.ref(Foo('x'))
produces this error:
Traceback (most recent call last):
File "slotsref.py", line 8, in <module>
weakref.ref(Foo('x'))
TypeError: cannot create weak reference to 'Foo' object
In the docs for __slots__, it says "Without a __weakref__ variable for each instance, classes defining __slots__ do not support weak references to its instances. If weak reference support is needed, then add '__weakref__' to the sequence of strings in the __slots__ declaration."
Adding '__weakref__' to the list isn't hard, but I wanted to see if people had any opinions about whether this should happen transparently, or if you should have to opt-in to it by saying @attr.s(weakref=True).
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels