@@ -14,7 +14,7 @@ msgid ""
1414msgstr ""
1515"Project-Id-Version : Python 3.9\n "
1616"Report-Msgid-Bugs-To : \n "
17- "POT-Creation-Date : 2021-05-07 06:17 +0000\n "
17+ "POT-Creation-Date : 2021-05-11 06:18 +0000\n "
1818"PO-Revision-Date : 2018-06-29 21:06+0000\n "
1919"
Last-Translator :
Freesand Leo <[email protected] >, 2021\n "
2020"Language-Team : Chinese (China) (https://www.transifex.com/python-doc/teams/5390/zh_CN/)\n "
@@ -588,18 +588,33 @@ msgstr "在其他用途中,这允许初始化依赖于一个或多个其他字
588588
589589#: ../../library/dataclasses.rst:425
590590msgid ""
591+ "The :meth:`__init__` method generated by :func:`dataclass` does not call "
592+ "base class :meth:`__init__` methods. If the base class has an "
593+ ":meth:`__init__` method that has to be called, it is common to call this "
594+ "method in a :meth:`__post_init__` method::"
595+ msgstr ""
596+
597+ #: ../../library/dataclasses.rst:442
598+ msgid ""
599+ "Note, however, that in general the dataclass-generated :meth:`__init__` "
600+ "methods don't need to be called, since the derived dataclass will take care "
601+ "of initializing all fields of any base class that is a dataclass itself."
602+ msgstr ""
603+
604+ #: ../../library/dataclasses.rst:446
605+ msgid ""
591606"See the section below on init-only variables for ways to pass parameters to "
592607":meth:`__post_init__`. Also see the warning about how :func:`replace` "
593608"handles ``init=False`` fields."
594609msgstr ""
595610"有关将参数传递给 :meth:`__post_init__` 的方法,请参阅下面有关仅初始化变量的段落。另请参阅关于 :func:`replace` "
596611"处理 ``init=False`` 字段的警告。"
597612
598- #: ../../library/dataclasses.rst:430
613+ #: ../../library/dataclasses.rst:451
599614msgid "Class variables"
600615msgstr "类变量"
601616
602- #: ../../library/dataclasses.rst:432
617+ #: ../../library/dataclasses.rst:453
603618msgid ""
604619"One of two places where :func:`dataclass` actually inspects the type of a "
605620"field is to determine if a field is a class variable as defined in "
@@ -613,11 +628,11 @@ msgstr ""
613628" ``typing.ClassVar`` 来完成此操作。如果一个字段是一个 ``ClassVar`` "
614629",它将被排除在考虑范围之外,并被数据类机制忽略。这样的 ``ClassVar`` 伪字段不会由模块级的 :func:`fields` 函数返回。"
615630
616- #: ../../library/dataclasses.rst:441
631+ #: ../../library/dataclasses.rst:462
617632msgid "Init-only variables"
618633msgstr "仅初始化变量"
619634
620- #: ../../library/dataclasses.rst:443
635+ #: ../../library/dataclasses.rst:464
621636msgid ""
622637"The other place where :func:`dataclass` inspects a type annotation is to "
623638"determine if a field is an init-only variable. It does this by seeing if "
@@ -634,25 +649,25 @@ msgstr ""
634649"函数返回。仅初始化字段作为参数添加到生成的 :meth:`__init__` 方法中,并传递给可选的 :meth:`__post_init__` "
635650"方法。数据类不会使用它们。"
636651
637- #: ../../library/dataclasses.rst:453
652+ #: ../../library/dataclasses.rst:474
638653msgid ""
639654"For example, suppose a field will be initialized from a database, if a value"
640655" is not provided when creating the class::"
641656msgstr "例如,假设一个字段将从数据库初始化,如果在创建类时未提供其值::"
642657
643- #: ../../library/dataclasses.rst:468
658+ #: ../../library/dataclasses.rst:489
644659msgid ""
645660"In this case, :func:`fields` will return :class:`Field` objects for ``i`` "
646661"and ``j``, but not for ``database``."
647662msgstr ""
648663"在这种情况下, :func:`fields` 将返回 ``i`` 和 ``j`` 的 :class:`Field` 对象,但不包括 "
649664"``database`` 。"
650665
651- #: ../../library/dataclasses.rst:472
666+ #: ../../library/dataclasses.rst:493
652667msgid "Frozen instances"
653668msgstr "冻结的实例"
654669
655- #: ../../library/dataclasses.rst:474
670+ #: ../../library/dataclasses.rst:495
656671msgid ""
657672"It is not possible to create truly immutable Python objects. However, by "
658673"passing ``frozen=True`` to the :meth:`dataclass` decorator you can emulate "
@@ -664,7 +679,7 @@ msgstr ""
664679"装饰器,你可以模拟不变性。在这种情况下,数据类将向类添加 :meth:`__setattr__` 和 :meth:`__delattr__` 方法。 "
665680"些方法在调用时会引发 :exc:`FrozenInstanceError` 。"
666681
667- #: ../../library/dataclasses.rst:480
682+ #: ../../library/dataclasses.rst:501
668683msgid ""
669684"There is a tiny performance penalty when using ``frozen=True``: "
670685":meth:`__init__` cannot use simple assignment to initialize fields, and must"
@@ -673,11 +688,11 @@ msgstr ""
673688"使用 ``frozen=True`` 时会有很小的性能损失: :meth:`__ init__` 不能使用简单的赋值来初始化字段,并必须使用 "
674689":meth:`object.__ setattr__` 。"
675690
676- #: ../../library/dataclasses.rst:485
691+ #: ../../library/dataclasses.rst:506
677692msgid "Inheritance"
678693msgstr "继承"
679694
680- #: ../../library/dataclasses.rst:487
695+ #: ../../library/dataclasses.rst:508
681696msgid ""
682697"When the dataclass is being created by the :meth:`dataclass` decorator, it "
683698"looks through all of the class's base classes in reverse MRO (that is, "
@@ -692,22 +707,22 @@ msgstr ""
692707"),并且对于它找到的每个数据类, "
693708"将该基类中的字段添加到字段的有序映射中。添加完所有基类字段后,它会将自己的字段添加到有序映射中。所有生成的方法都将使用这种组合的,计算的有序字段映射。由于字段是按插入顺序排列的,因此派生类会重载基类。一个例子::"
694709
695- #: ../../library/dataclasses.rst:507
710+ #: ../../library/dataclasses.rst:528
696711msgid ""
697712"The final list of fields is, in order, ``x``, ``y``, ``z``. The final type "
698713"of ``x`` is ``int``, as specified in class ``C``."
699714msgstr ""
700715"最后的字段列表依次是 ``x`` 、 ``y`` 、 ``z`` 。 ``x`` 的最终类型是 ``int`` ,如类 ``C`` 中所指定的那样。"
701716
702- #: ../../library/dataclasses.rst:510
717+ #: ../../library/dataclasses.rst:531
703718msgid "The generated :meth:`__init__` method for ``C`` will look like::"
704719msgstr "为 ``C`` 生成的 :meth:`__init__` 方法看起来像::"
705720
706- #: ../../library/dataclasses.rst:515
721+ #: ../../library/dataclasses.rst:536
707722msgid "Default factory functions"
708723msgstr "默认工厂函数"
709724
710- #: ../../library/dataclasses.rst:517
725+ #: ../../library/dataclasses.rst:538
711726msgid ""
712727"If a :func:`field` specifies a ``default_factory``, it is called with zero "
713728"arguments when a default value for the field is needed. For example, to "
@@ -716,7 +731,7 @@ msgstr ""
716731"如果一个 :func:`field` 指定了一个 ``default_factory`` "
717732",当需要该字段的默认值时,将使用零参数调用它。例如,要创建列表的新实例,请使用::"
718733
719- #: ../../library/dataclasses.rst:523
734+ #: ../../library/dataclasses.rst:544
720735msgid ""
721736"If a field is excluded from :meth:`__init__` (using ``init=False``) and the "
722737"field also specifies ``default_factory``, then the default factory function "
@@ -727,31 +742,31 @@ msgstr ""
727742"``default_factory`` ,则默认的工厂函数将始终从生成的 :meth:`__ init__` "
728743"函数调用。发生这种情况是因为没有其他方法可以为字段提供初始值。"
729744
730- #: ../../library/dataclasses.rst:530
745+ #: ../../library/dataclasses.rst:551
731746msgid "Mutable default values"
732747msgstr "可变的默认值"
733748
734- #: ../../library/dataclasses.rst:532
749+ #: ../../library/dataclasses.rst:553
735750msgid ""
736751"Python stores default member variable values in class attributes. Consider "
737752"this example, not using dataclasses::"
738753msgstr "Python 在类属性中存储默认成员变量值。思考这个例子,不使用数据类::"
739754
740- #: ../../library/dataclasses.rst:547
755+ #: ../../library/dataclasses.rst:568
741756msgid ""
742757"Note that the two instances of class ``C`` share the same class variable "
743758"``x``, as expected."
744759msgstr "请注意,类 ``C`` 的两个实例共享相同的类变量 ``x`` ,如预期的那样。"
745760
746- #: ../../library/dataclasses.rst:550
761+ #: ../../library/dataclasses.rst:571
747762msgid "Using dataclasses, *if* this code was valid::"
748763msgstr "使用数据类, *如果* 此代码有效::"
749764
750- #: ../../library/dataclasses.rst:558
765+ #: ../../library/dataclasses.rst:579
751766msgid "it would generate code similar to::"
752767msgstr "它生成的代码类似于::"
753768
754- #: ../../library/dataclasses.rst:569
769+ #: ../../library/dataclasses.rst:590
755770msgid ""
756771"This has the same issue as the original example using class ``C``. That is, "
757772"two instances of class ``D`` that do not specify a value for ``x`` when "
@@ -767,17 +782,17 @@ msgstr ""
767782"``list`` 、 ``dict`` 或 ``set`` 的默认参数,则会引发 :exc:`TypeError` "
768783"。这是一个部分解决方案,但它可以防止许多常见错误。"
769784
770- #: ../../library/dataclasses.rst:579
785+ #: ../../library/dataclasses.rst:600
771786msgid ""
772787"Using default factory functions is a way to create new instances of mutable "
773788"types as default values for fields::"
774789msgstr "使用默认工厂函数是一种创建可变类型新实例的方法,并将其作为字段的默认值::"
775790
776- #: ../../library/dataclasses.rst:589
791+ #: ../../library/dataclasses.rst:610
777792msgid "Exceptions"
778793msgstr "异常"
779794
780- #: ../../library/dataclasses.rst:593
795+ #: ../../library/dataclasses.rst:614
781796msgid ""
782797"Raised when an implicitly defined :meth:`__setattr__` or :meth:`__delattr__`"
783798" is called on a dataclass which was defined with ``frozen=True``. It is a "
0 commit comments