@@ -480,16 +480,22 @@ msgid ""
480
480
"may not work correctly. (Specifically, you may not be able to create "
481
481
"instances of such subclasses without getting a :exc:`TypeError`.)"
482
482
msgstr ""
483
+ "如果你要创建一个协作 :c:member:`~PyTypeObject.tp_new` (它会调用基类型的 "
484
+ ":c:member:`~PyTypeObject.tp_new` 或 :meth:`__new__`),那么你 *不能* "
485
+ "在运行时尝试使用方法解析顺序来确定要调用的方法。 必须总是静态地确定你要调用的类型,并直接调用它的 "
486
+ ":c:member:`~PyTypeObject.tp_new`,或是通过 ``type->tp_base->tp_new``。 "
487
+ "如果你不这样做,你的类型的同样从其他 Python 定义的类继承的 Python 子类可能无法正确工作。 "
488
+ "(特别地,你可能无法创建这样的子类的实例而是会引发 :exc:`TypeError`。)"
483
489
484
490
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/extending/newtypes_tutorial.rst:363
485
491
msgid ""
486
492
"We also define an initialization function which accepts arguments to provide"
487
493
" initial values for our instance::"
488
- msgstr ""
494
+ msgstr "我们还定义了一个接受参数来为我们的实例提供初始值的初始化函数:: "
489
495
490
496
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/extending/newtypes_tutorial.rst:392
491
497
msgid "by filling the :c:member:`~PyTypeObject.tp_init` slot. ::"
492
- msgstr ""
498
+ msgstr "通过填充 :c:member:`~PyTypeObject.tp_init` 槽位。 :: "
493
499
494
500
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/extending/newtypes_tutorial.rst:396
495
501
msgid ""
@@ -498,6 +504,8 @@ msgid ""
498
504
"created. Initializers always accept positional and keyword arguments, and "
499
505
"they should return either ``0`` on success or ``-1`` on error."
500
506
msgstr ""
507
+ ":c:member:`~PyTypeObject.tp_init` 槽位在 Python 中暴露为 :meth:`__init__` 方法。 "
508
+ "它被用来在对象被创建后初始化它。 初始化器总是接受位置和关键字参数,它们应当在成功时返回 ``0`` 而在出错时返回 ``-1``。"
501
509
502
510
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/extending/newtypes_tutorial.rst:401
503
511
msgid ""
@@ -509,6 +517,10 @@ msgid ""
509
517
"values. We might be tempted, for example to assign the ``first`` member "
510
518
"like this::"
511
519
msgstr ""
520
+ "不同于 ``tp_new`` 处理句柄,``tp_init`` 不保证一定会被调用 (例如,在默认情况下 :mod:`pickle` "
521
+ "模块不会在被解封的实例上调用 :meth:`__init__`)。 它还可能被多次调用。 任何人都可以在我们的对象上调用 "
522
+ ":meth:`__init__` 方法。 由于这个原因,我们在为属性赋新值时必须非常小心。 我们可能会被误导,例如像这样给 ``first`` "
523
+ "成员赋值::"
512
524
513
525
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/extending/newtypes_tutorial.rst:415
514
526
msgid ""
0 commit comments