@@ -2961,6 +2961,10 @@ msgid ""
2961
2961
":meth:`!__len__` nor :meth:`!__bool__` (which is true of the :class:`object`"
2962
2962
" class itself), all its instances are considered true."
2963
2963
msgstr ""
2964
+ "调用此方法以实现真值检测以及内置的 ``bool()`` 操作;应当返回 ``False`` 或 ``True``。 当未定义此方法时,则会在定义了 "
2965
+ ":meth:`~object.__len__` 的情况下调用它,如果其结果不为零则该对象将被视为具有真值。 如果一个类的 "
2966
+ ":meth:`!__len__` 和 :meth:`!__bool__` 均未定义(这也是 :class:`object` "
2967
+ "类本身的情况),则其所有实例都将被视为具有真值。"
2964
2968
2965
2969
#: ../../reference/datamodel.rst:2210
2966
2970
msgid "Customizing attribute access"
@@ -2983,6 +2987,10 @@ msgid ""
2983
2987
"attribute value or raise an :exc:`AttributeError` exception. The "
2984
2988
":class:`object` class itself does not provide this method."
2985
2989
msgstr ""
2990
+ "当默认属性访问因引发 :exc:`AttributeError` 而失败时被调用 (可能是调用 :meth:`__getattribute__` 时由于"
2991
+ " *name* 不是一个实例属性或 ``self`` 的类层级树中的属性而引发了 :exc:`AttributeError`;或者是由于 *name* "
2992
+ "特征属性的 :meth:`__get__` 引发了 :exc:`AttributeError`)。 此方法应当返回(找到的)属性值或是引发一个 "
2993
+ ":exc:`AttributeError` 异常。 :class:`object` 类本身没有提供此方法。"
2986
2994
2987
2995
#: ../../reference/datamodel.rst:2228
2988
2996
msgid ""
@@ -3191,6 +3199,9 @@ msgid ""
3191
3199
" the owner class' :attr:`~object.__dict__`. The :class:`object` class "
3192
3200
"itself does not implement any of these protocols."
3193
3201
msgstr ""
3202
+ "下列方法仅当一个包含该方法的类(即所谓 *描述器* 类)的实例出现在一个 *所有者* "
3203
+ "类之中的时候才会起作用(该描述器必须在所有者类或它的某个上级类的类字典中)。 在下面的例子中,“属性”是指名称为所有者类的 "
3204
+ ":attr:`~object.__dict__` 中的特征属性的键名的属性。 :class:`object` 类本身没有实现这些协议。"
3194
3205
3195
3206
#: ../../reference/datamodel.rst:2370
3196
3207
msgid ""
@@ -3476,6 +3487,9 @@ msgid ""
3476
3487
":attr:`~object.__dict__` and *__weakref__* unless the subclass also defines "
3477
3488
"*__slots__* (which should only contain names of any *additional* slots)."
3478
3489
msgstr ""
3490
+ "*__slots__* 声明的作用不只限于定义它的类。 在父类中声明的 *__slots__* 在其子类中同样可用。 不过,子类的实例将会获得 "
3491
+ ":attr:`~object.__dict__` 和 *__weakref__*,除非子类也定义了 *__slots__* (它应当只包含 *附加* "
3492
+ "槽位的名称)。"
3479
3493
3480
3494
#: ../../reference/datamodel.rst:2565
3481
3495
msgid ""
@@ -4037,6 +4051,9 @@ msgid ""
4037
4051
"the context of adding Abstract Base Classes (see the :mod:`abc` module) to "
4038
4052
"the language."
4039
4053
msgstr ""
4054
+ "包括通过 :meth:`~type.__instancecheck__` 和 :meth:`~type.__subclasscheck__` 来定制 "
4055
+ ":func:`isinstance` 和 :func:`issubclass` 行为的说明,加入此功能的动机是出于向语言添加抽象基类的场景(参见 "
4056
+ ":mod:`abc` 模块)。"
4040
4057
4041
4058
#: ../../reference/datamodel.rst:2906
4042
4059
msgid "Emulating generic types"
@@ -4323,6 +4340,8 @@ msgid ""
4323
4340
"defined, ``x(arg1, arg2, ...)`` roughly translates to ``type(x).__call__(x, "
4324
4341
"arg1, ...)``. The :class:`object` class itself does not provide this method."
4325
4342
msgstr ""
4343
+ "此方法会在实例作为一个函数被“调用”时被调用;如果定义了此方法,则 ``x(arg1, arg2, ...)`` 大致可以被转写为 "
4344
+ "``type(x).__call__(x, arg1, ...)``。 :class:`object` 类本身没有提供此方法。"
4326
4345
4327
4346
#: ../../reference/datamodel.rst:3064
4328
4347
msgid "Emulating container types"
@@ -4365,6 +4384,26 @@ msgid ""
4365
4384
"container; for mappings, :meth:`!__iter__` should iterate through the "
4366
4385
"object's keys; for sequences, it should iterate through the values."
4367
4386
msgstr ""
4387
+ "可以定义下列方法来实现容器对象。 :class:`object` 类本身没有提供它们。 容器通常是 :term:`序列 <sequence>` (如 "
4388
+ ":class:`列表 <list>` 或 :class:`元组 <tuple>`) 或者 :term:`映射 <mapping>` (如 "
4389
+ ":term:`字典 <dictionary>`),但也存在其他的容器表示形式。 "
4390
+ "前面的一组方法被用来模拟序列或模拟映射;两者的区别在于序列所允许的键应为整数 *k* 且 ``0 <= k < N`` 其中 *N* "
4391
+ "为整个序列或者定义条目范围的 :class:`slice` 对象的长度。 此外还建议让映射提供 :meth:`!keys`, "
4392
+ ":meth:`!values`, :meth:`!items`, :meth:`!get`, :meth:`!clear`, "
4393
+ ":meth:`!setdefault`, :meth:`!pop`, :meth:`!popitem`, :meth:`!copy` 以及 "
4394
+ ":meth:`!update` 等方法,它们的行为应与 Python 的标准 :class:`字典 <dict>` 对象的类似。 "
4395
+ ":mod:`collections.abc` 模块提供了一个 :class:`~collections.abc.MutableMapping` "
4396
+ ":term:`abstract base class` 以根据由 :meth:`~object.__getitem__`, "
4397
+ ":meth:`~object.__setitem__`, :meth:`~object.__delitem__` 和 :meth:`!keys` "
4398
+ "组成的基本集来创建这些方法。 可变序列应当提供 :meth:`!append`, :meth:`!count`, :meth:`!index`, "
4399
+ ":meth:`!extend`, :meth:`!insert`, :meth:`!pop`, :meth:`!remove`, "
4400
+ ":meth:`!reverse` 和 :meth:`!sort` 等方法,就像 Python 标准 :class:`list` 对象那样。 "
4401
+ "最后,序列类型还应当通过定义下文描述的 :meth:`~object.__add__`, :meth:`~object.__radd__`, "
4402
+ ":meth:`~object.__iadd__`, :meth:`~object.__mul__`, :meth:`~object.__rmul__` "
4403
+ "和 :meth:`~object.__imul__` 等方法来实现加法(即拼接)和乘法(即重复);它们不应定义其他数值运算符。 "
4404
+ "此外还建议映射和序列都实现 :meth:`~object.__contains__` 方法以允许高效地使用 ``in`` 运算符;对于映射,``in``"
4405
+ " 应当搜索映射的键;对于序列,则应当搜索其中的值。 另外还建议映射和序列都实现 :meth:`~object.__iter__` "
4406
+ &quo
4761
t;方法以允许高效地迭代容器;对于映射,:meth:`!__iter__` 应当迭代对象的键;对于序列,则应当迭代其中的值。"
4368
4407
4369
4408
#: ../../reference/datamodel.rst:3108
4370
4409
msgid ""
0 commit comments