Why cannot I use __slots__ and weakrefs together?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sun May 27 00:47:02 EDT 2018


On Sat, 26 May 2018 11:53:42 +0200, Christian Heimes wrote:

>> Why does weakref hate my Eggs class?
> 
> Weakref needs some place to store reference information. It works if you
> add "__weakref__" to your slots:
> 
> class Eggs:
>      __slots__ = ['spanish_inquisition', '__weakref__']


Thanks!






-- 
Steven D'Aprano
"Ever since I learned about confirmation bias, I've been seeing
it everywhere." -- Jon Ronson




More information about the Python-list mailing list