Why weakref doesn't support built-in types in Python?

前端 未结 2 728
南笙
南笙 2021-01-04 11:05

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

Several built-in types such as list and dict do not directly

相关标签:
2条回答
  • 2021-01-04 11:40

    Most of the built-in types are not directly weak referenceable (e.g. str, int, float, list, dict, None), and there are a few that cannot even be made so by sub-classing (e.g. tuples in CPython).

    Some details about the underlying implementation of weakrefs for several built-in types can be found in this March-2005 python-list post by Raymond Hettinger.

    0 讨论(0)
  • 2021-01-04 11:46

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

    0 讨论(0)
提交回复
热议问题