@@ -72,6 +72,12 @@ msgid ""
7272"collection can reclaim the object, and its corresponding entries in weak "
7373"mappings are simply deleted."
7474msgstr ""
75+ "例如,如果您有许多大型二进制图像对象,则可能希望将名称与每个对象关联起来。如果您使用Python字典将名称映射到图像,或将图像映射到名称,则图像对象将保持活动状态,因为它们在字典中显示为值或键。"
76+ " :mod:`weakref` 模块提供的 :class:`WeakKeyDictionary` 和 "
77+ ":class:`WeakValueDictionary` "
78+ "类可以替代Python字典,使用弱引用来构造映射,这些映射不会仅仅因为它们出现在映射对象中而使对象保持存活。例如,如果一个图像对象是 "
79+ ":class:`WeakValueDictionary` "
80+ "中的值,那么当对该图像对象的剩余引用是弱映射对象所持有的弱引用时,垃圾回收可以回收该对象并将其在弱映射对象中相应的条目删除。"
7581
7682#: ../../library/weakref.rst:48
7783msgid ""
@@ -82,6 +88,9 @@ msgid ""
8288":class:`set` interface, but keeps weak references to its elements, just like"
8389" a :class:`WeakKeyDictionary` does."
8490msgstr ""
91+ ":class:`WeakKeyDictionary` 和 :class:`WeakValueDictionary` "
92+ "在它们的实现中使用弱引用,在弱引用上设置回调函数,当键或值被垃圾回收回收时通知弱字典。 :class:`WeakSet` 实现了 "
93+ ":class:`set` 接口,但像 :class:`WeakKeyDictionary` 一样,只持有其元素的弱引用。`"
8594
8695#: ../../library/weakref.rst:55
8796msgid ""
@@ -91,6 +100,8 @@ msgid ""
91100"the module automatically ensures that the finalizer remains alive until the "
92101"object is collected."
93102msgstr ""
103+ ":class:`finalize` "
104+ "提供了注册一个对象被垃圾收集时要调用的清理函数的方式。这比在原始弱引用上设置回调函数更简单,因为模块会自动确保对象被回收前终结器一直保持存活。"
94105
95106#: ../../library/weakref.rst:61
96107msgid ""
@@ -99,6 +110,8 @@ msgid ""
99110"your own weak references directly. The low-level machinery is exposed by "
100111"the :mod:`weakref` module for the benefit of advanced uses."
101112msgstr ""
113+ "这些弱容器类型之一或者 :class:`finalize` 就是大多数程序所需要的 - 通常不需要直接创建自己的弱引用。:mod:`weakref` "
114+ "模块暴露了低级机制,以便于高级用途。"
102115
103116#: ../../library/weakref.rst:66
104117msgid ""
@@ -108,29 +121,34 @@ msgid ""
108121":term:`generator`\\ s, type objects, sockets, arrays, deques, regular "
109122"expression pattern objects, and code objects."
110123msgstr ""
124+ "并非所有对象都可以被弱引用;那些可以包含类实例的对象,用Python编写的函数(不是用C语言编写的),实例方法,集合,frozensets,某些 "
125+ ":term:`file objects <file object>` , :term:`生成器` "
126+ ",类型对象,套接字,数组,双端队列,正则表达式模式对象和代码对象。"
111127
112128#: ../../library/weakref.rst:72
113129msgid "Added support for thread.lock, threading.Lock, and code objects."
114- msgstr ""
130+ msgstr "添加了对thread.lock,threading.Lock和代码对象的支持。 "
115131
116132#: ../../library/weakref.rst:75
117133msgid ""
118134"Several built-in types such as :class:`list` and :class:`dict` do not "
119135"directly support weak references but can add support through subclassing::"
120- msgstr ""
136+ msgstr "几个内建类型如 :class:`list` 和 :class:`dict` 不直接支持弱引用,但可以通过子类化添加支持:: "
121137
122138#: ../../library/weakref.rst:83
123139msgid ""
124140"Other built-in types such as :class:`tuple` and :class:`int` do not support "
125141"weak references even when subclassed (This is an implementation detail and "
126142"may be different across various Python implementations.)."
127143msgstr ""
144+ "其他内建类型如 :class:`tuple` 和 :class:`int` "
145+ "即使在子类化时也不支持弱引用(这是一个实现细节,在各种Python实现中可能不同)。"
128146
129147#: ../../library/weakref.rst:87
130148msgid ""
131149"Extension types can easily be made to support weak references; see :ref"
132150":`weakref-support`."
133- msgstr ""
151+ msgstr " 可以轻松地使用扩展类型来支持弱引用;参见 :ref:`weakref-support`。 "
134152
135153#: ../../library/weakref.rst:93
136154msgid ""
@@ -143,6 +161,9 @@ msgid ""
143161"object will be passed as the only parameter to the callback; the referent "
144162"will no longer be available."
145163msgstr ""
164+ "返回对 *对象* 的弱引用。如果原始对象仍然存活,则可以通过调用引用对象来检索原始对象;如果引用的原始对象不再存在,则调用引用对象将得到 "
165+ ":const:`None` 。如果提供了 *回调* 而且值不是 :const:`None` "
166+ ",并且返回的弱引用对象仍然存活,则在对象即将终结时将调用回调;弱引用对象将作为回调的唯一参数传递;指示物将不再可用。"
146167
147168#: ../../library/weakref.rst:101
148169msgid ""
0 commit comments