Expand Up @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.10\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2022-01-09 00:10+0000\n" "POT-Creation-Date: 2022-02-10 00:10+0000\n" "PO-Revision-Date: 2018-07-15 18:56+0800\n" "Last-Translator: \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" Expand Down Expand Up @@ -537,18 +537,18 @@ msgid "" "type is :const:`KW_ONLY`." msgstr "" #: ../../library/dataclasses.rst:480 #: ../../library/dataclasses.rst:482 msgid "" "Raised when an implicitly defined :meth:`__setattr__` or :meth:`__delattr__` " "is called on a dataclass which was defined with ``frozen=True``. It is a " "subclass of :exc:`AttributeError`." msgstr "" #: ../../library/dataclasses.rst:485 #: ../../library/dataclasses.rst:487 msgid "Post-init processing" msgstr "" #: ../../library/dataclasses.rst:487 #: ../../library/dataclasses.rst:489 msgid "" "The generated :meth:`__init__` code will call a method named :meth:" "`__post_init__`, if :meth:`__post_init__` is defined on the class. It will " Expand All @@ -558,39 +558,39 @@ msgid "" "generated, then :meth:`__post_init__` will not automatically be called." msgstr "" #: ../../library/dataclasses.rst:495 #: ../../library/dataclasses.rst:497 msgid "" "Among other uses, this allows for initializing field values that depend on " "one or more other fields. For example::" msgstr "" #: ../../library/dataclasses.rst:507 #: ../../library/dataclasses.rst:509 msgid "" "The :meth:`__init__` method generated by :func:`dataclass` does not call " "base class :meth:`__init__` methods. If the base class has an :meth:" "`__init__` method that has to be called, it is common to call this method in " "a :meth:`__post_init__` method::" msgstr "" #: ../../library/dataclasses.rst:524 #: ../../library/dataclasses.rst:526 msgid "" "Note, however, that in general the dataclass-generated :meth:`__init__` " "methods don't need to be called, since the derived dataclass will take care " "of initializing all fields of any base class that is a dataclass itself." msgstr "" #: ../../library/dataclasses.rst:528 #: ../../library/dataclasses.rst:530 msgid "" "See the section below on init-only variables for ways to pass parameters to :" "meth:`__post_init__`. Also see the warning about how :func:`replace` " "handles ``init=False`` fields." msgstr "" #: ../../library/dataclasses.rst:533 #: ../../library/dataclasses.rst:535 msgid "Class variables" msgstr "" #: ../../library/dataclasses.rst:535 #: ../../library/dataclasses.rst:537 msgid "" "One of two places where :func:`dataclass` actually inspects the type of a " "field is to determine if a field is a class variable as defined in :pep:" Expand All @@ -600,11 +600,11 @@ msgid "" "pseudo-fields are not returned by the module-level :func:`fields` function." msgstr "" #: ../../library/dataclasses.rst:544 #: ../../library/dataclasses.rst:546 msgid "Init-only variables" msgstr "" #: ../../library/dataclasses.rst:546 #: ../../library/dataclasses.rst:548 msgid "" "The other place where :func:`dataclass` inspects a type annotation is to " "determine if a field is an init-only variable. It does this by seeing if " Expand All @@ -616,23 +616,23 @@ msgid "" "`__post_init__` method. They are not otherwise used by dataclasses." msgstr "" #: ../../library/dataclasses.rst:556 #: ../../library/dataclasses.rst:558 msgid "" "For example, suppose a field will be initialized from a database, if a value " "is not provided when creating the class::" msgstr "" #: ../../library/dataclasses.rst:571 #: ../../library/dataclasses.rst:573 msgid "" "In this case, :func:`fields` will return :class:`Field` objects for ``i`` " "and ``j``, but not for ``database``." msgstr "" #: ../../library/dataclasses.rst:575 #: ../../library/dataclasses.rst:577 msgid "Frozen instances" msgstr "" #: ../../library/dataclasses.rst:577 #: ../../library/dataclasses.rst:579 msgid "" "It is not possible to create truly immutable Python objects. However, by " "passing ``frozen=True`` to the :meth:`dataclass` decorator you can emulate " Expand All @@ -641,18 +641,18 @@ msgid "" "`FrozenInstanceError` when invoked." msgstr "" #: ../../library/dataclasses.rst:583 #: ../../library/dataclasses.rst:585 msgid "" "There is a tiny performance penalty when using ``frozen=True``: :meth:" "`__init__` cannot use simple assignment to initialize fields, and must use :" "meth:`object.__setattr__`." msgstr "" #: ../../library/dataclasses.rst:588 #: ../../library/dataclasses.rst:590 msgid "Inheritance" msgstr "" #: ../../library/dataclasses.rst:590 #: ../../library/dataclasses.rst:592 msgid "" "When the dataclass is being created by the :meth:`dataclass` decorator, it " "looks through all of the class's base classes in reverse MRO (that is, " Expand All @@ -664,95 +664,95 @@ msgid "" "derived classes override base classes. An example::" msgstr "" #: ../../library/dataclasses.rst:610 #: ../../library/dataclasses.rst:612 msgid "" "The final list of fields is, in order, ``x``, ``y``, ``z``. The final type " "of ``x`` is ``int``, as specified in class ``C``." msgstr "" #: ../../library/dataclasses.rst:613 #: ../../library/dataclasses.rst:615 msgid "The generated :meth:`__init__` method for ``C`` will look like::" msgstr "" #: ../../library/dataclasses.rst:618 #: ../../library/dataclasses.rst:620 msgid "Re-ordering of keyword-only parameters in :meth:`__init__`" msgstr "" #: ../../library/dataclasses.rst:620 #: ../../library/dataclasses.rst:622 msgid "" "After the parameters needed for :meth:`__init__` are computed, any keyword-" "only parameters are moved to come after all regular (non-keyword-only) " "parameters. This is a requirement of how keyword-only parameters are " "implemented in Python: they must come after non-keyword-only parameters." msgstr "" #: ../../library/dataclasses.rst:626 #: ../../library/dataclasses.rst:628 msgid "" "In this example, ``Base.y``, ``Base.w``, and ``D.t`` are keyword-only " "fields, and ``Base.x`` and ``D.z`` are regular fields::" msgstr "" #: ../../library/dataclasses.rst:641 #: ../../library/dataclasses.rst:643 msgid "The generated :meth:`__init__` method for ``D`` will look like::" msgstr "" #: ../../library/dataclasses.rst:645 #: ../../library/dataclasses.rst:647 msgid "" "Note that the parameters have been re-ordered from how they appear in the " "list of fields: parameters derived from regular fields are followed by " "parameters derived from keyword-only fields." msgstr "" #: ../../library/dataclasses.rst:649 #: ../../library/dataclasses.rst:651 msgid "" "The relative ordering of keyword-only parameters is maintained in the re-" "ordered :meth:`__init__` parameter list." msgstr "" #: ../../library/dataclasses.rst:654 #: ../../library/dataclasses.rst:656 msgid "Default factory functions" msgstr "" #: ../../library/dataclasses.rst:656 #: ../../library/dataclasses.rst:658 msgid "" "If a :func:`field` specifies a ``default_factory``, it is called with zero " "arguments when a default value for the field is needed. For example, to " "create a new instance of a list, use::" msgstr "" #: ../../library/dataclasses.rst:662 #: ../../library/dataclasses.rst:664 msgid "" "If a field is excluded from :meth:`__init__` (using ``init=False``) and the " "field also specifies ``default_factory``, then the default factory function " "will always be called from the generated :meth:`__init__` function. This " "happens because there is no other way to give the field an initial value." msgstr "" #: ../../library/dataclasses.rst:669 #: ../../library/dataclasses.rst:671 msgid "Mutable default values" msgstr "" #: ../../library/dataclasses.rst:671 #: ../../library/dataclasses.rst:673 msgid "" "Python stores default member variable values in class attributes. Consider " "this example, not using dataclasses::" msgstr "" #: ../../library/dataclasses.rst:686 #: ../../library/dataclasses.rst:688 msgid "" "Note that the two instances of class ``C`` share the same class variable " "``x``, as expected." msgstr "" #: ../../library/dataclasses.rst:689 #: ../../library/dataclasses.rst:691 msgid "Using dataclasses, *if* this code was valid::" msgstr "" #: ../../library/dataclasses.rst:697 #: ../../library/dataclasses.rst:699 msgid "it would generate code similar to::" msgstr "" #: ../../library/dataclasses.rst:708 #: ../../library/dataclasses.rst:710 msgid "" "This has the same issue as the original example using class ``C``. That is, " "two instances of class ``D`` that do not specify a value for ``x`` when " Expand All @@ -765,7 +765,7 @@ msgid "" "errors." msgstr "" #: ../../library/dataclasses.rst:719 #: ../../library/dataclasses.rst:721 msgid "" "Using default factory functions is a way to create new instances of mutable " "types as default values for fields::" Expand Down