Why doesn't weakref support inline types in Python?

The Python weakref document ( http://docs.python.org/library/weakref.html ) says that

Several built-in types, such as list and dict, do not directly support weak references, but can add support through subclasses

I think creating a weakref for a big dict might be useful in some real cases. I am wondering what is the reason for this implementation?

+7
source share
2 answers

Most built-in types are not directly weak reference ones (e.g. str, int, float, list, dict, None), and there are some of them that cannot even be made by subclassing (e.g. tuples in CPython).

Some information on the basic weakrefs implementation for several built-in types can be found in this March 2005 python-brand report by Raymond Hettinger .

+6
source

My educated guess is that dicts and lists are used internally to implement weakrefs, so you will have an egg situation.

0
source

All Articles