@@ -2162,6 +2162,8 @@ msgid ""
21622162"of strings that represents the names accessible on module. If present, this "
21632163"function overrides the standard :func:`dir` search on a module."
21642164msgstr ""
2165+ "``__dir__`` 函数应当不接受任何参数,并且返回一个表示模块中可访问名称的字符串序列。 此函数如果存在,将会重载一个模块中的标准 "
2166+ ":func:`dir` 查找。"
21652167
21662168#: ../../reference/datamodel.rst:1570
21672169msgid ""
@@ -2511,7 +2513,7 @@ msgid ""
25112513"If an iterator is used for *__slots__* then a descriptor is created for each"
25122514" of the iterator's values. However, the *__slots__* attribute will be an "
25132515"empty iterator."
2514- msgstr ""
2516+ msgstr "如果为 *__slots__* 使用了一个迭代器,则会为迭代器的每个值创建描述器。 但是 *__slots__* 属性将为一个空迭代器。 "
25152517
25162518#: ../../reference/datamodel.rst:1793
25172519msgid "Customizing class creation"
@@ -2970,6 +2972,22 @@ msgid ""
29702972":meth:`__iter__` should iterate through the object's keys; for sequences, it"
29712973" should iterate through the values."
29722974msgstr ""
2975+ "可以定义下列方法来实现容器对象。 容器通常属于序列(如列表或元组)或映射(如字典),但也存在其他形式的容器。 "
2976+ "前几个方法集被用于模拟序列或是模拟映射;两者的不同之处在于序列允许的键应为整数 *k* 且 ``0 <= k < N`` 其中 *N* "
2977+ "是序列或定义指定区间的项的切片对象的长度。 此外还建议让映射提供 :meth:`keys`, :meth:`values`, "
2978+ ":meth:`items`, :meth:`get`, :meth:`clear`, :meth:`setdefault`, :meth:`pop`, "
2979+ ":meth:`popitem`, :meth:`!copy` 以及 :meth:`update` 等方法,它们的行为应与 Python "
2980+ "标准字典对象的相应方法类似。 此外 :mod:`collections.abc` 模块提供了一个 "
2981+ ":class:`~collections.abc.MutableMapping` 抽象基类以便根据由 :meth:`__getitem__`, "
2982+ ":meth:`__setitem__`, :meth:`__delitem__`, 和 :meth:`keys` 组成的基本集来创建所需的方法。 "
2983+ "可变序列还应像 Python 标准列表对象那样提供 :meth:`append`, :meth:`count`, :meth:`index`, "
2984+ ":meth:`extend`, :meth:`insert`, :meth:`pop`, :meth:`remove`, :meth:`reverse`"
2985+ " 和 :meth:`sort` 等方法。 最后,序列类型还应通过定义下文描述的 :meth:`__add__`, :meth:`__radd__`, "
2986+ ":meth:`__iadd__`, :meth:`__mul__`, :meth:`__rmul__` 和 :meth:`__imul__` "
2987+ "等方法来实现加法(指拼接)和乘法(指重复);它们不应定义其他数值运算符。 此外还建议映射和序列都实现 :meth:`__contains__` "
2988+ "方法以允许高效地使用 ``in`` 运算符;对于映射,``in`` 应该搜索映射的键;对于序列,则应搜索其中的值。 另外还建议映射和序列都实现 "
2989+ ":meth:`__iter__` 方法以允许高效地迭代容器中的条目;对于映射,:meth:`__iter__` "
2990+ "应当迭代对象的键;对于序列,则应当迭代其中的值。"
29732991
29742992#: ../../reference/datamodel.rst:2131
29752993msgid ""
@@ -3118,6 +3136,8 @@ msgid ""
31183136" objects can supply the following special method with a more efficient "
31193137"implementation, which also does not require the object be iterable."
31203138msgstr ""
3139+ "成员检测运算符 (:keyword:`in` 和 :keyword:`not in`) 通常以对容器进行逐个迭代的方式来实现。 "
3140+ "不过,容器对象可以提供以下特殊方法并采用更有效率的实现,这样也不要求对象必须为可迭代对象。"
31213141
31223142#: ../../reference/datamodel.rst:2243
31233143msgid ""
0 commit comments