为什么weakref 不支持Python 中的内置类型? [英] Why weakref doesn't support built-in types in Python?

查看:37
本文介绍了为什么weakref 不支持Python 中的内置类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Python 弱引用文档中(http://docs.python.org/library/weakref.html ),它说

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

list、dict等几种内置类型不直接支持弱引用但可以通过子类化添加支持

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

我认为为 big dict 创建 weakref 在某些实际情况下可能很有用.我想知道该实施背后的原因是什么?

I think creating weakref for big dict could be useful in some real cases. I'm wondering what's the reason behind that implementation ?

推荐答案

大多数内置类型都不是直接弱引用的(例如 str、int、float、list、dict、None),还有一些甚至不能通过子类化(例如 CPython 中的元组)来实现.

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).

可以在 Raymond Hettinger 于 2005 年 3 月发布的 Python 列表帖子.

这篇关于为什么weakref 不支持Python 中的内置类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆