@@ -381,6 +381,10 @@ msgid ""
381
381
"object's type might not be :class:`CustomType`, because the object may be an"
382
382
" instance of a subclass."
383
383
msgstr ""
384
+ "此方法会先清空两个 Python 属性的引用计数。 :c:func:`Py_XDECREF` 可正确地处理其参数为 ``NULL`` 的情况(这可能在 "
385
+ "``tp_new`` 中途失败时发生)。 随后它将调用对象类型的 :c:member:`~PyTypeObject.tp_free` 成员(通过 "
386
+ "``Py_TYPE(self)`` 获取对象类型)来释放对象的内存。 请注意对象类型可以不是 "
387
+ ":class:`CustomType`,因为对象可能是一个子类的实例。"
384
388
385
389
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/extending/newtypes_tutorial.rst:285
386
390
msgid ""
@@ -390,16 +394,19 @@ msgid ""
390
394
"argument. Otherwise, the compiler will emit a warning. This is object-"
391
395
"oriented polymorphism, in C!"
392
396
msgstr ""
397
+ "上面需要强制转换 ``destructor`` 是因为我们定义了 ``Custom_dealloc`` 接受一个 ``CustomObject *`` "
398
+ "参数,但 ``tp_dealloc`` 函数指针预期接受一个 ``PyObject *`` 参数。 如果不这样做,编译器将发出警告。 这是 C "
399
+ "语言中面向对象的多态性!"
393
400
394
401
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/extending/newtypes_tutorial.rst:291
395
402
msgid ""
396
403
"We want to make sure that the first and last names are initialized to empty "
397
404
"strings, so we provide a ``tp_new`` implementation::"
398
- msgstr ""
405
+ msgstr "我们希望确保头一个和末一个名称被初始化为空字符串,因此我们提供了一个 ``tp_new`` 实现:: "
399
406
400
407
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/extending/newtypes_tutorial.rst:315
401
408
msgid "and install it in the :c:member:`~PyTypeObject.tp_new` member::"
402
- msgstr ""
409
+ msgstr "并在 :c:member:`~PyTypeObject.tp_new` 成员中安装它:: "
403
410
404
411
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/extending/newtypes_tutorial.rst:319
405
412
msgid ""
@@ -411,6 +418,10 @@ msgid ""
411
418
"type above. In this case, we use the ``tp_new`` handler to initialize the "
412
419
"``first`` and ``last`` attributes to non-``NULL`` default values."
413
420
msgstr ""
421
+ "``tp_new`` 处理句柄负责创建(而不是初始化)该类型的对象。 它在 Python 中被暴露为 :meth:`__new__` 方法。 "
422
+ "它不需要定义 ``tp_new`` 成员,实际上许多扩展类型会简单地重用 :c:func:`PyType_GenericNew`,就像上面第一版 "
423
+ "``Custom`` 类型所作的那样。 在此情况下,我们使用 ``tp_new`` 处理句柄来将 ``first`` 和 ``last`` "
424
+ "属性初始化为非 ``NULL`` 的默认值。"
414
425
415
426
#: /home/runner/work/docspush-transifex/docspush-transifex/cpython/Doc/extending/newtypes_tutorial.rst:327
416
427
msgid ""
0 commit comments