4
4
msgstr ""
5
5
"Project-Id-Version : Python 3.12\n "
6
6
"Report-Msgid-Bugs-To : \n "
7
- "POT-Creation-Date : 2024-05-21 00:03+0000\n "
7
+ "POT-Creation-Date : 2024-05-24 00:03+0000\n "
8
8
"PO-Revision-Date : 2023-02-11 15:02+0800\n "
9
9
"Last-Translator : \n "
10
10
"Language-Team : Chinese - TAIWAN (https://github.com/python/python-docs-zh- "
@@ -324,13 +324,17 @@ msgid ""
324
324
"*slots*: If true (the default is ``False``), :attr:`~object.__slots__` "
325
325
"attribute will be generated and new class will be returned instead of the "
326
326
"original one. If :attr:`!__slots__` is already defined in the class, then :"
327
- "exc:`TypeError` is raised."
327
+ "exc:`TypeError` is raised. Calling no-arg :func:`super` in dataclasses using "
328
+ "``slots=True`` will result in the following exception being raised: "
329
+ "``TypeError: super(type, obj): obj must be an instance or subtype of type``. "
330
+ "The two-arg :func:`super` is a valid workaround. See :gh:`90562` for full "
331
+ "details."
328
332
msgstr ""
329
333
"``slots``:如果為 true(預設為 ``False``),將生成 :attr:`~object.__slots__` "
330
334
"屬性並回傳新類而不是原始類。如果 :attr:`!__slots__` 已經在類中定義,則 :exc:"
331
335
"`TypeError` 被引發。"
332
336
333
- #: ../../library/dataclasses.rst:192
337
+ #: ../../library/dataclasses.rst:195
334
338
#, fuzzy
335
339
msgid ""
336
340
"If a field name is already included in the :attr:`!__slots__` of a base "
@@ -346,7 +350,7 @@ msgstr ""
346
350
"夠確定繼承的插槽,基底類別 :attr:`!__slots__` 可以是任何可疊代的,但*不是*疊"
347
351
"代器。"
348
352
349
- #: ../../library/dataclasses.rst:202
353
+ #: ../../library/dataclasses.rst:205
350
354
#, fuzzy
351
355
msgid ""
352
356
"*weakref_slot*: If true (the default is ``False``), add a slot named "
@@ -358,14 +362,14 @@ msgstr ""
358
362
"插槽,這是使實例可弱引用所必需的。在沒有指定 ``slots=True`` 的情況下指定 "
359
363
"``weakref_slot=True`` 是錯誤的。"
360
364
361
- #: ../../library/dataclasses.rst:209
365
+ #: ../../library/dataclasses.rst:212
362
366
#, fuzzy
363
367
msgid ""
364
368
"``field``\\ s may optionally specify a default value, using normal Python "
365
369
"syntax::"
366
370
msgstr "``field``\\ s 可以選擇指定一個預設值,使用普通的 Python 語法: ::"
367
371
368
- #: ../../library/dataclasses.rst:217
372
+ #: ../../library/dataclasses.rst:220
369
373
#, fuzzy
370
374
msgid ""
371
375
"In this example, both :attr:`!a` and :attr:`!b` will be included in the "
@@ -374,7 +378,7 @@ msgstr ""
374
378
"在此示例中,:attr:`!a` 和 :attr:`!b` 都將包含在新增的 :meth:`~object."
375
379
"__init__` 方法中,該方法將定義為: ::"
376
380
377
- #: ../../library/dataclasses.rst:222
381
+ #: ../../library/dataclasses.rst:225
378
382
#, fuzzy
379
383
msgid ""
380
384
":exc:`TypeError` will be raised if a field without a default value follows a "
@@ -384,7 +388,7 @@ msgstr ""
384
388
":exc:`TypeError` 如果沒有預設值的欄位跟在具有預設值的欄位之後,將引發。無論這"
385
389
"發生在單個類中還是作為類繼承的結果,都是如此。"
386
390
387
- #: ../../library/dataclasses.rst:228
391
+ #: ../../library/dataclasses.rst:231
388
392
#, fuzzy
389
393
msgid ""
390
394
"For common and simple use cases, no other functionality is required. There "
@@ -397,7 +401,7 @@ msgstr ""
397
401
"位資訊。為了滿足這種對附加資訊的需求,你可以通過呼叫提供的 :func:`!field` 函"
398
402
"式來替換預設欄位值。例如: ::"
399
403
400
- #: ../../library/dataclasses.rst:241
404
+ #: ../../library/dataclasses.rst:244
401
405
#, fuzzy
402
406
msgid ""
403
407
"As shown above, the :const:`MISSING` value is a sentinel object used to "
@@ -409,11 +413,11 @@ msgstr ""
409
413
"供。使用此標記是因為“None”對於某些具有不同含義的參數是有效值。任何程式碼都不"
410
414
"應直接使用 :const:`MISSING` 值。"
411
415
412
- #: ../../library/dataclasses.rst:246
416
+ #: ../../library/dataclasses.rst:249
413
417
msgid "The parameters to :func:`!field` are:"
414
418
msgstr ":func:`!field` 的參數是:"
415
419
416
- #: ../../library/dataclasses.rst:248
420
+ #: ../../library/dataclasses.rst:251
417
421
#, fuzzy
418
422
msgid ""
419
423
"*default*: If provided, this will be the default value for this field. This "
@@ -423,7 +427,7 @@ msgstr ""
423
427
"*default*:如果提供,這將是該欄位的預設值。這是必需的,因為 :meth:`!field` 呼"
424
428
"叫本身會替換預設值的正常位置。"
425
429
426
- #: ../../library/dataclasses.rst:252
430
+ #: ../../library/dataclasses.rst:255
427
431
#, fuzzy
428
432
msgid ""
429
433
"*default_factory*: If provided, it must be a zero-argument callable that "
@@ -436,7 +440,7 @@ msgstr ""
436
440
"時將被呼叫。除其他用途外,這可用於指定具有可變預設值的欄位,如下所述。同時指"
437
441
"定 *default* 和 *default_factory* 是錯誤的。"
438
442
439
- #: ../../library/dataclasses.rst:258
443
+ #: ../../library/dataclasses.rst:261
440
444
#, fuzzy
441
445
msgid ""
442
446
"*init*: If true (the default), this field is included as a parameter to the "
@@ -445,7 +449,7 @@ msgstr ""
445
449
"*init*:如果為 true(預設值),則此欄位將作為生成的 :meth:`~object.__init__` "
446
450
"方法的參數包含在內。"
447
451
448
- #: ../../library/dataclasses.rst:261
452
+ #: ../../library/dataclasses.rst:264
449
453
#, fuzzy
450
454
msgid ""
451
455
"*repr*: If true (the default), this field is included in the string returned "
@@ -454,7 +458,7 @@ msgstr ""
454
458
"*repr*:如果為真(預設值),則此欄位包含在生成的 :meth:`~object.__repr__` 方"
455
459
"法回傳的字串中。"
456
460
457
- #: ../../library/dataclasses.rst:264
461
+ #: ../../library/dataclasses.rst:267
458
462
#, fuzzy
459
463
msgid ""
460
464
"*hash*: This can be a bool or ``None``. If true, this field is included in "
@@ -468,7 +472,7 @@ msgstr ""
468
472
"如果一個欄位用於比較,則應在雜湊中考慮該欄位。不鼓勵將此值設定為“無”以外的任"
469
473
"何值。"
470
474
471
- #: ../../library/dataclasses.rst:271
475
+ #: ../../library/dataclasses.rst:274
472
476
#, fuzzy
473
477
msgid ""
474
478
"One possible reason to set ``hash=False`` but ``compare=True`` would be if a "
@@ -481,7 +485,7 @@ msgstr ""
481
485
"湊值的成本很高,則需要該欄位進行相等性測試,並且還有其他欄位有助於型別的雜湊"
482
486
"值。即使一個欄位被排除在雜湊之外,它仍然會被用於比較。"
483
487
484
- #: ../../library/dataclasses.rst:277
488
+ #: ../../library/dataclasses.rst:280
485
489
#, fuzzy
486
490
msgid ""
487
491
"*compare*: If true (the default), this field is included in the generated "
@@ -491,7 +495,7 @@ msgstr ""
491
495
"*compare*:如果為真(預設值),則此欄位包含在生成的相等和比較方法中(:meth:"
492
496
"`~object.__eq__`、:meth:`~object.__gt__` 等)。"
493
497
494
- #: ../../library/dataclasses.rst:281
498
+ #: ../../library/dataclasses.rst:284
495
499
#, fuzzy
496
500
msgid ""
497
501
"*metadata*: This can be a mapping or ``None``. ``None`` is treated as an "
@@ -506,7 +510,7 @@ msgstr ""
506
510
"不被資料類別使用,而是作為第三方擴充機制提供的。多個第三方可以各自擁有自己的"
507
511
"密鑰,用作元資料中的命名空間。"
508
512
509
- #: ../../library/dataclasses.rst:289
513
+ #: ../../library/dataclasses.rst:292
510
514
#, fuzzy
511
515
msgid ""
512
516
"*kw_only*: If true, this field will be marked as keyword-only. This is used "
@@ -515,7 +519,7 @@ msgstr ""
515
519
"*kw_only*:如果為真,該欄位將被標記為僅限關鍵字。這在計算生成的 :meth:"
516
520
"`~object.__init__` 方法的參數時使用。"
517
521
518
- #: ../../library/dataclasses.rst:295
522
+ #: ../../library/dataclasses.rst:298
519
523
#, fuzzy
520
524
msgid ""
521
525
"If the default value of a field is specified by a call to :func:`!field`, "
@@ -531,7 +535,7 @@ msgstr ""
531
535
"在 :func:`@dataclass <dataclass>` 裝飾器運行後,類別屬性將全部包含欄位的預設"
532
536
"值,就像預設值本身已指定一樣。例如,在: ::"
533
537
534
- #: ../../library/dataclasses.rst:311
538
+ #: ../../library/dataclasses.rst:314
535
539
#, fuzzy
536
540
msgid ""
537
541
"The class attribute :attr:`!C.z` will be ``10``, the class attribute :attr:`!"
@@ -541,7 +545,7 @@ msgstr ""
541
545
"類別屬性 :attr:`!C.z` 將為 ``10``,類別屬性 :attr:`!C.t` 將為 ``20``,類別屬"
542
546
"性 :attr:`!C.x` 和 :attr:`!C.y` 將不會放。"
543
547
544
- #: ../../library/dataclasses.rst:317
548
+ #: ../../library/dataclasses.rst:320
545
549
#, fuzzy
546
550
msgid ""
547
551
":class:`!Field` objects describe each defined field. These objects are "
@@ -553,15 +557,15 @@ msgstr ""
553
557
"`fields` 模組級方法回傳(見下文)。使用者不應該直接實例化 :class:`!Field` 物"
554
558
"件。它記錄的屬性是:"
555
559
556
- #: ../../library/dataclasses.rst:322
560
+ #: ../../library/dataclasses.rst:325
557
561
msgid ":attr:`!name`: The name of the field."
558
562
msgstr ":attr:`!name`:欄位的名稱。"
559
563
560
- #: ../../library/dataclasses.rst:323
564
+ #: ../../library/dataclasses.rst:326
561
565
msgid ":attr:`!type`: The type of the field."
562
566
msgstr ":attr:`!type`:欄位的型別。"
563
567
564
- #: ../../library/dataclasses.rst:324
568
+ #: ../../library/dataclasses.rst:327
565
569
#, fuzzy
566
570
msgid ""
567
571
":attr:`!default`, :attr:`!default_factory`, :attr:`!init`, :attr:`!repr`, :"
@@ -572,14 +576,14 @@ msgstr ""
572
576
"attr:`!hash`、:attr:`!compare`, :attr:`!metadata` 和 :attr:`!kw_only` 有與它"
573
577
"們在 :func:`field` 函式中的含義和值相同。"
574
578
575
- #: ../../library/dataclasses.rst:328
579
+ #: ../../library/dataclasses.rst:331
576
580
#, fuzzy
577
581
msgid ""
578
582
"Other attributes may exist, but they are private and must not be inspected "
579
583
"or relied on."
580
584
msgstr "可能存在其他屬性,但它們是私有的,不得檢查或依賴。"
581
585
582
- #: ../../library/dataclasses.rst:333
586
+ #: ../../library/dataclasses.rst:336
583
587
#, fuzzy
584
588
msgid ""
585
589
"Returns a tuple of :class:`Field` objects that define the fields for this "
@@ -591,7 +595,7 @@ msgstr ""
591
595
"實例。如果未傳遞資料類別或其中一個實例,則引發 :exc:`TypeError`。不回傳 "
592
596
"``ClassVar`` 或 ``InitVar`` 的偽欄位。"
593
597
594
- #: ../../library/dataclasses.rst:340
598
+ #: ../../library/dataclasses.rst:343
595
599
#, fuzzy
596
600
msgid ""
597
601
"Converts the dataclass *obj* to a dict (by using the factory function "
@@ -603,23 +607,23 @@ msgstr ""
603
607
"都被轉換為其欄位的字典,作為 ``name: value`` 對。資料類別、字典、列表和元組被"
604
608
"遞迴到。其他物件使用 :func:`copy.deepcopy` 複製。"
605
609
606
- #: ../../library/dataclasses.rst:346
610
+ #: ../../library/dataclasses.rst:349
607
611
#, fuzzy
608
612
msgid "Example of using :func:`!asdict` on nested dataclasses::"
609
613
msgstr "在嵌套資料類別上使用 :func:`!asdict` 的範例: ::"
610
614
611
- #: ../../library/dataclasses.rst:363 ../../library/dataclasses.rst:383
615
+ #: ../../library/dataclasses.rst:366 ../../library/dataclasses.rst:386
612
616
#, fuzzy
613
617
msgid "To create a shallow copy, the following workaround may be used::"
614
618
msgstr "要建立淺複製,可以使用以下解決方法:"
615
619
616
- #: ../../library/dataclasses.rst:367
620
+ #: ../../library/dataclasses.rst:370
617
621
#, fuzzy
618
622
msgid ""
619
623
":func:`!asdict` raises :exc:`TypeError` if *obj* is not a dataclass instance."
620
624
msgstr ":func:`!asdict` 如果 *obj* 不是資料類別實例,則引發 :exc:`TypeError`。"
621
625
622
- #: ../../library/dataclasses.rst:372
626
+ #: ../../library/dataclasses.rst:375
623
627
#, fuzzy
624
628
msgid ""
625
629
"Converts the dataclass *obj* to a tuple (by using the factory function "
@@ -631,19 +635,19 @@ msgstr ""
631
635
"都被轉換為其欄位值的元組。資料類別、字典、列表和元組被遞迴到。其他物件使用 :"
632
636
"func:`copy.deepcopy` 複製。"
633
637
634
- #: ../../library/dataclasses.rst:378
638
+ #: ../../library/dataclasses.rst:381
635
639
msgid "Continuing from the previous example::"
636
640
msgstr "從前面的例子繼續: ::"
637
641
638
- #: ../../library/dataclasses.rst:387
642
+ #: ../../library/dataclasses.rst:390
639
643
#, fuzzy
640
644
msgid ""
641
645
":func:`!astuple` raises :exc:`TypeError` if *obj* is not a dataclass "
642
646
"instance."
643
647
msgstr ""
644
648
":func:`!astuple` 如果 *obj* 不是資料類別實例,則引發 :exc:`TypeError`。"
645
649
646
- #: ../../library/dataclasses.rst:392
650
+ #: ../../library/dataclasses.rst:395
647
651
#, fuzzy
648
652
msgid ""
649
653
"Creates a new dataclass with name *cls_name*, fields as defined in *fields*, "
@@ -663,13 +667,13 @@ msgstr ""
663
667
"``kw_only`` 的值, ``slots`` 和 ``weakref_slot`` 與它們在 :func:`dataclass` 中"
664
668
"的含義相同。"
665
669
666
- #: ../../library/dataclasses.rst:402
670
+ #: ../../library/dataclasses.rst:405
667
671
msgid ""
668
672
"If *module* is defined, the :attr:`!__module__` attribute of the dataclass "
669
673
"is set to that value. By default, it is set to the module name of the caller."
670
674
msgstr ""
671
675
672
- #: ../../library/dataclasses.rst:406
676
+ #: ../../library/dataclasses.rst:409
673
677
#, fuzzy
674
678
msgid ""
675
679
"This function is not strictly required, because any Python mechanism for "
@@ -681,11 +685,11 @@ msgstr ""
681
685
"制都可以應用 :func:`dataclass` 函式將該類轉換為資料類別。提供此功能是為了方"
682
686
"便。例如: ::"
683
687
684
- #: ../../library/dataclasses.rst:418
688
+ #: ../../library/dataclasses.rst:421
685
689
msgid "Is equivalent to::"
686
690
msgstr "相當於: ::"
687
691
688
- #: ../../library/dataclasses.rst:431
692
+ #: ../../library/dataclasses.rst:434
689
693
#, fuzzy
690
694
msgid ""
691
695
"Creates a new object of the same type as *obj*, replacing fields with values "
@@ -697,7 +701,7 @@ msgstr ""
697
701
"``obj`` 不是資料類別,則引發 :exc:`TypeError`。如果 ``changes`` 中的值未指定"
698
702
"欄位,則引發 :exc:`TypeError`。"
699
703
700
- #: ../../library/dataclasses.rst:436
704
+ #: ../../library/dataclasses.rst:439
701
705
#, fuzzy
702
706
msgid ""
703
707
"The newly returned object is created by calling the :meth:`~object.__init__` "
@@ -707,7 +711,7 @@ msgstr ""
707
711
"新回傳的對像是通過呼叫資料類別的 :meth:`~object.__init__` 方法建立的。這確"
708
712
"保 :meth:`__post_init__`(如果存在)也被呼叫。"
709
713
710
- #: ../../library/dataclasses.rst:440
714
+ #: ../../library/dataclasses.rst:443
711
715
#, fuzzy
712
716
msgid ""
713
717
"Init-only variables without default values, if any exist, must be specified "
@@ -717,7 +721,7 @@ msgstr ""
717
721
"沒有預設值的僅初始化變數(如果存在)必須在呼叫 :func:`replace` 時指定,以便它"
718
722
"們可以傳遞給 :meth:`__init__` 和 :meth:`__post_init__`。"
719
723
720
- #: ../../library/dataclasses.rst:444
724
+ #: ../../library/dataclasses.rst:447
721
725
#, fuzzy
722
726
msgid ""
723
727
"It is an error for *changes* to contain any fields that are defined as "
@@ -726,7 +730,7 @@ msgstr ""
726
730
"*changes* 包含任何定義為具有 ``init=False`` 的欄位是錯誤的。在這種情況下將引"
727
731
"發 :exc:`ValueError`。"
728
732
729
- #: ../../library/dataclasses.rst:448
733
+ #: ../../library/dataclasses.rst:451
730
734
#, fuzzy
731
735
msgid ""
732
736
"Be forewarned about how ``init=False`` fields work during a call to :func:`!"
@@ -743,15 +747,15 @@ msgstr ""
743
747
"造函式可能是明智的,或者可能是處理實例複製的自定義:func:`!replace` (或類似命"
744
748
"名的)方法。"
745
749
746
- #: ../../library/dataclasses.rst:459
750
+ #: ../../library/dataclasses.rst:462
747
751
#, fuzzy
748
752
msgid ""
749
753
"Return ``True`` if its parameter is a dataclass or an instance of one, "
750
754
"otherwise return ``False``."
751
755
msgstr ""
752
756
"如果它的參數是一個資料類別或一個實例,則回傳 ``True``,否則回傳 ``False``。"
753
757
754
- #: ../../library/dataclasses.rst:462
758
+ #: ../../library/dataclasses.rst:465
755
759
#, fuzzy
756
760
msgid ""
757
761
"If you need to know if a class is an instance of a dataclass (and not a "
@@ -761,12 +765,12 @@ msgstr ""
761
765
"如果你需要知道一個類是否是資料類別的實例(而不是資料類別本身),那麼新增一個"
762
766
"進一步的檢查 ``not isinstance(obj, type)``: ::"
763
767
764
- #: ../../library/dataclasses.rst:471
768
+ #: ../../library/dataclasses.rst:474
765
769
#, fuzzy
766
770
msgid "A sentinel value signifying a missing default or default_factory."
767
771
msgstr "表示缺少 default 或 default_factory 的標記值。"
768
772
769
- #: ../../library/dataclasses.rst:475
773
+ #: ../../library/dataclasses.rst:478
770
774
#, fuzzy
771
775
msgid ""
772
776
"A sentinel value used as a type annotation. Any fields after a pseudo-field "
@@ -782,21 +786,21 @@ msgstr ""
782
786
"類欄位的名稱。按照慣例,名稱 ``_`` 用於 :const:`!KW_ONLY` 欄位。僅關鍵字欄位"
783
787
"表示 :meth:`~object.__init__` 參數,在實例化類時必須將其指定為關鍵字。"
784
788
785
- #: ../../library/dataclasses.rst:484
789
+ #: ../../library/dataclasses.rst:487
786
790
#, fuzzy
787
791
msgid ""
788
792
"In this example, the fields ``y`` and ``z`` will be marked as keyword-only "
789
793
"fields::"
790
794
msgstr "在此示例中,欄位 ``y`` 和 ``z`` 將被標記為僅關鍵字欄位: ::"
791
795
792
- #: ../../library/dataclasses.rst:495
796
+ #: ../../library/dataclasses.rst:498
793
797
#, fuzzy
794
798
msgid ""
795
799
"In a single dataclass, it is an error to specify more than one field whose "
796
800
"type is :const:`!KW_ONLY`."
797
801
msgstr "在單個資料類別中,指定多個型別為 :const:`!KW_ONLY` 的欄位是錯誤的。"
798
802
799
- #: ../../library/dataclasses.rst:502
803
+ #: ../../library/dataclasses.rst:505
800
804
#, fuzzy
801
805
msgid ""
802
806
"Raised when an implicitly defined :meth:`~object.__setattr__` or :meth:"
@@ -806,12 +810,12 @@ msgstr ""
806
810
"當在使用 frozen=True 定義的資料類別上呼叫隱式定義的 :meth:`__setattr__` 或 :"
807
811
"meth:`__delattr__` 時引發。它是 :exc:`AttributeError` 的子類別。"
808
812
809
- #: ../../library/dataclasses.rst:509
813
+ #: ../../library/dataclasses.rst:512
810
814
#, fuzzy
811
815
msgid "Post-init processing"
812
816
msgstr "初始化後處理"
813
817
814
- #: ../../library/dataclasses.rst:513
818
+ #: ../../library/dataclasses.rst:516
815
819
#, fuzzy
816
820
msgid ""
817
821
"When defined on the class, it will be called by the generated :meth:`~object."
@@ -827,14 +831,14 @@ msgstr ""
827
831
"按照它們在類中定義的順序傳遞給 :meth:`!__post_init__` 。如果沒有生成 :meth:`!"
828
832
"__init__` 方法,那麼 :meth:`!__post_init__` 將不會被自動呼叫。"
829
833
830
- #: ../../library/dataclasses.rst:520
834
+ #: ../../library/dataclasses.rst:523
831
835
#, fuzzy
832
836
msgid ""
833
837
"Among other uses, this allows for initializing field values that depend on "
834
838
"one or more other fields. For example::"
835
839
msgstr "在其他用途中,這允許初始化依賴於一個或多個其他欄位的欄位值。例如: ::"
836
840
837
- #: ../../library/dataclasses.rst:532
841
+ #: ../../library/dataclasses.rst:535
838
842
#, fuzzy
839
843
msgid ""
840
844
"The :meth:`~object.__init__` method generated by :func:`@dataclass "
@@ -846,7 +850,7 @@ msgstr ""
846
850
"類別 :meth:`!__init__` 方法。如果基底類別有一個必須呼叫的 :meth:`!__init__` "
847
851
"方法,通常在 :meth:`__post_init__` 方法中呼叫此方法: ::"
848
852
849
- #: ../../library/dataclasses.rst:549
853
+ #: ../../library/dataclasses.rst:552
850
854
#, fuzzy
851
855
msgid ""
852
856
"Note, however, that in general the dataclass-generated :meth:`!__init__` "
@@ -856,7 +860,7 @@ msgstr ""
856
860
"但是請注意,通常不需要呼叫資料類別生成的 :meth:`!__init__` 方法,因為派生資料"
857
861
"類別將負責初始化作為資料類別本身的任何基底類別的所有欄位。"
858
862
859
- #: ../../library/dataclasses.rst:553
863
+ #: ../../library/dataclasses.rst:556
860
864
#, fuzzy
861
865
msgid ""
862
866
"See the section below on init-only variables for ways to pass parameters to :"
@@ -866,11 +870,11 @@ msgstr ""
866
870
"請參閱下面有關僅初始化變數的部分,了解將參數傳遞給 :meth:`!__post_init__` 的"
867
871
"方法。另請參閱有關 :func:`replace` 如何處理 ``init=False`` 欄位的警告。"
868
872
869
- #: ../../library/dataclasses.rst:560
873
+ #: ../../library/dataclasses.rst:563
870
874
msgid "Class variables"
871
875
msgstr "類別變數"
872
876
873
- #: ../../library/dataclasses.rst:562
877
+ #: ../../library/dataclasses.rst:565
874
878
#, fuzzy
875
879
msgid ""
876
880
"One of the few places where :func:`@dataclass <dataclass>` actually inspects "
@@ -887,12 +891,12 @@ msgstr ""
887
891
"外,並被資料類別機制忽略。模組級 :func:`fields` 函式不會回傳此類別 "
888
892
"``ClassVar`` 偽欄位。"
889
893
890
- #: ../../library/dataclasses.rst:573
894
+ #: ../../library/dataclasses.rst:576
891
895
#, fuzzy
892
896
msgid "Init-only variables"
893
897
msgstr "僅初始化變數"
894
898
895
- #: ../../library/dataclasses.rst:575
899
+ #: ../../library/dataclasses.rst:578
896
900
#, fuzzy
897
901
msgid ""
898
902
"Another place where :func:`@dataclass <dataclass>` inspects a type "
@@ -912,14 +916,14 @@ msgstr ""
912
916
"的 :meth:`~object.__init__` 方法,並傳遞給可選的 :meth:`__post_init__` 方法。"
913
917
"它們不被資料類使用。"
914
918
915
- #: ../../library/dataclasses.rst:585
919
+ #: ../../library/dataclasses.rst:588
916
920
#, fuzzy
917
921
msgid ""
918
922
"For example, suppose a field will be initialized from a database, if a value "
919
923
"is not provided when creating the class::"
920
924
msgstr "例如,假設一個欄位將從資料庫中初始化,如果在建立類時沒有提供值: ::"
921
925
922
- #: ../../library/dataclasses.rst:600
926
+ #: ../../library/dataclasses.rst:603
923
927
#, fuzzy
924
928
msgid ""
925
929
"In this case, :func:`fields` will return :class:`Field` objects for :attr:`!"
@@ -928,11 +932,11 @@ msgstr ""
928
932
"在這種情況下,:func:`fields` 將為 :attr:`!i` 和 :attr:`!j` 回傳 :class:"
929
933
"`Field` 物件,但不會為 :attr:`!database` 回傳。"
930
934
931
- #: ../../library/dataclasses.rst:606
935
+ #: ../../library/dataclasses.rst:609
932
936
msgid "Frozen instances"
933
937
msgstr "凍結實例"
934
938
935
- #: ../../library/dataclasses.rst:608
939
+ #: ../../library/dataclasses.rst:611
936
940
#, fuzzy
937
941
msgid ""
938
942
"It is not possible to create truly immutable Python objects. However, by "
@@ -946,7 +950,7 @@ msgstr ""
946
950
"別將向類新增 :meth:`~object.__setattr__` 和 :meth:`~object.__delattr__` 方"
947
951
"法。這些方法在呼叫時會引發 :exc:`FrozenInstanceError`。"
948
952
949
- #: ../../library/dataclasses.rst:614
953
+ #: ../../library/dataclasses.rst:617
950
954
#, fuzzy
951
955
msgid ""
952
956
"There is a tiny performance penalty when using ``frozen=True``: :meth:"
@@ -956,11 +960,11 @@ msgstr ""
956
960
"使用 ``frozen=True`` 時有一個微小的性能損失::meth:`~object.__init__` 不能使"
957
961
"用簡單賦值來初始化欄位,必須使用 :meth:`!object.__setattr__`。"
958
962
959
- #: ../../library/dataclasses.rst:623
963
+ #: ../../library/dataclasses.rst:626
960
964
msgid "Inheritance"
961
965
msgstr "繼承"
962
966
963
- #: ../../library/dataclasses.rst:625
967
+ #: ../../library/dataclasses.rst:628
964
968
#, fuzzy
965
969
msgid ""
966
970
"When the dataclass is being created by the :func:`@dataclass <dataclass>` "
@@ -978,7 +982,7 @@ msgstr ""
978
982
"將自己的欄位新增到有序映射中。所有生成的方法都將使用這種組合的、計算的有序欄"
979
983
"位映射。因為欄位是按插入順序排列的,所以派生類會覆蓋基底類別。一個例子: ::"
980
984
981
- #: ../../library/dataclasses.rst:645
985
+ #: ../../library/dataclasses.rst:648
982
986
#, fuzzy
983
987
msgid ""
984
988
"The final list of fields is, in order, :attr:`!x`, :attr:`!y`, :attr:`!z`. "
@@ -988,19 +992,19 @@ msgstr ""
988
992
"最終的欄位列表按順序為 :attr:`!x`、:attr:`!y`、:attr:`!z`。:attr:`!x` 的最終"
989
993
"型別是 :class:`int`,如類別 :class:`!C` 中指定的那樣。"
990
994
991
- #: ../../library/dataclasses.rst:648
995
+ #: ../../library/dataclasses.rst:651
992
996
#, fuzzy
993
997
msgid ""
994
998
"The generated :meth:`~object.__init__` method for :class:`!C` will look "
995
999
"like::"
996
1000
msgstr "為 :class:`!C` 生成的 :meth:`~object.__init__` 方法將如下所示: ::"
997
1001
998
- #: ../../library/dataclasses.rst:653
1002
+ #: ../../library/dataclasses.rst:656
999
1003
#, fuzzy
1000
1004
msgid "Re-ordering of keyword-only parameters in :meth:`!__init__`"
1001
1005
msgstr ":meth:`!__init__` 中僅關鍵字參數的重新排序"
1002
1006
1003
- #: ../../library/dataclasses.rst:655
1007
+ #: ../../library/dataclasses.rst:658
1004
1008
#, fuzzy
1005
1009
msgid ""
1006
1010
"After the parameters needed for :meth:`~object.__init__` are computed, any "
@@ -1012,7 +1016,7 @@ msgstr ""
1012
1016
"僅關鍵字)參數之後。這是如何在 Python 中實作僅關鍵字參數的要求:它們必須位於"
1013
1017
"非僅關鍵字參數之後。"
1014
1018
1015
- #: ../../library/dataclasses.rst:661
1019
+ #: ../../library/dataclasses.rst:664
1016
1020
#, fuzzy
1017
1021
msgid ""
1018
1022
"In this example, :attr:`!Base.y`, :attr:`!Base.w`, and :attr:`!D.t` are "
@@ -1022,12 +1026,12 @@ msgstr ""
1022
1026
"在此示例中,:attr:`!Base.y`、:attr:`!Base.w` 和 :attr:`!D.t` 是僅限關鍵字的欄"
1023
1027
"位,:attr:`!Base.x` 和 :attr:`!D.z` 是常規欄位: ::"
1024
1028
1025
- #: ../../library/dataclasses.rst:676
1029
+ #: ../../library/dataclasses.rst:679
1026
1030
#, fuzzy
1027
1031
msgid "The generated :meth:`!__init__` method for :class:`!D` will look like::"
1028
1032
msgstr "為 :class:`!D` 生成的 :meth:`!__init__` 方法將如下所示: ::"
1029
1033
1030
- #: ../../library/dataclasses.rst:680
1034
+ #: ../../library/dataclasses.rst:683
1031
1035
#, fuzzy
1032
1036
msgid ""
1033
1037
"Note that the parameters have been re-ordered from how they appear in the "
@@ -1037,18 +1041,18 @@ msgstr ""
1037
1041
"請注意,參數已根據它們在欄位列表中的顯示方式重新排序:從常規欄位派生的參數後"
1038
1042
"跟從僅關鍵字欄位派生的參數。"
1039
1043
1040
- #: ../../library/dataclasses.rst:684
1044
+ #: ../../library/dataclasses.rst:687
1041
1045
#, fuzzy
1042
1046
msgid ""
1043
1047
"The relative ordering of keyword-only parameters is maintained in the re-"
1044
1048
"ordered :meth:`!__init__` parameter list."
1045
1049
msgstr "僅關鍵字參數的相對順序在重新排序的 :meth:`!__init__` 參數列表中維護。"
1046
1050
1047
- #: ../../library/dataclasses.rst:689
1051
+ #: ../../library/dataclasses.rst:692
1048
1052
msgid "Default factory functions"
1049
1053
msgstr "預設工廠函式"
1050
1054
1051
- #: ../../library/dataclasses.rst:691
1055
+ #: ../../library/dataclasses.rst:694
1052
1056
#, fuzzy
1053
1057
msgid ""
1054
1058
"If a :func:`field` specifies a *default_factory*, it is called with zero "
@@ -1058,7 +1062,7 @@ msgstr ""
1058
1062
"如果 :func:`field` 指定了 *default_factory*,當需要該欄位的預設值時,它會以零"
1059
1063
"引數呼叫。例如,要建立列表的新實例,請使用: ::"
1060
1064
1061
- #: ../../library/dataclasses.rst:697
1065
+ #: ../../library/dataclasses.rst:700
1062
1066
#, fuzzy
1063
1067
msgid ""
1064
1068
"If a field is excluded from :meth:`~object.__init__` (using ``init=False``) "
@@ -1071,19 +1075,19 @@ msgstr ""
1071
1075
"位還指定了 ``default_factory``,那麼預設工廠函式將始終從生成的 :meth:"
1072
1076
"`__init__ 中呼叫`功能。發生這種情況是因為沒有其他方法可以為該欄位賦予初始值。"
1073
1077
1074
- #: ../../library/dataclasses.rst:704
1078
+ #: ../../library/dataclasses.rst:707
1075
1079
msgid "Mutable default values"
1076
1080
msgstr "可變預設值"
1077
1081
1078
- #: ../../library/dataclasses.rst:706
1082
+ #: ../../library/dataclasses.rst:709
1079
1083
#, fuzzy
1080
1084
msgid ""
1081
1085
"Python stores default member variable values in class attributes. Consider "
1082
1086
"this example, not using dataclasses::"
1083
1087
msgstr ""
1084
1088
"Python 將預設成員變數值存儲在類別屬性中。考慮這個例子,不使用資料類別: ::"
1085
1089
1086
- #: ../../library/dataclasses.rst:721
1090
+ #: ../../library/dataclasses.rst:724
1087
1091
#, fuzzy
1088
1092
msgid ""
1089
1093
"Note that the two instances of class :class:`!C` share the same class "
@@ -1092,16 +1096,16 @@ msgstr ""
1092
1096
"請注意,類別 :class:`!C` 的兩個實例共享同一個類別變數 :attr:`!x`,正如預期的"
1093
1097
"那樣。"
1094
1098
1095
- #: ../../library/dataclasses.rst:724
1099
+ #: ../../library/dataclasses.rst:727
1096
1100
#, fuzzy
1097
1101
msgid "Using dataclasses, *if* this code was valid::"
1098
1102
msgstr "使用資料類別,*如果*此程式碼有效: ::"
1099
1103
1100
- #: ../../library/dataclasses.rst:732
1104
+ #: ../../library/dataclasses.rst:735
1101
1105
msgid "it would generate code similar to::"
1102
1106
msgstr "它會生成類似的程式碼: ::"
1103
1107
1104
- #: ../../library/dataclasses.rst:743
1108
+ #: ../../library/dataclasses.rst:746
1105
1109
#, fuzzy
1106
1110
msgid ""
1107
1111
"This has the same issue as the original example using class :class:`!C`. "
@@ -1121,14 +1125,14 @@ msgstr ""
1121
1125
"到不可散列的預設參數,它將引發 :exc:`TypeError`。假設是如果一個值是不可散列"
1122
1126
"的,那麼它就是可變的。這是一個部分解決方案,但它確實可以防止許多常見錯誤。"
1123
1127
1124
- #: ../../library/dataclasses.rst:754
1128
+ #: ../../library/dataclasses.rst:757
1125
1129
#, fuzzy
1126
1130
msgid ""
1127
1131
"Using default factory functions is a way to create new instances of mutable "
1128
1132
"types as default values for fields::"
1129
1133
msgstr "使用預設工廠函式是一種建立可變型別的新實例作為欄位預設值的方法: ::"
1130
1134
1131
- #: ../../library/dataclasses.rst:763
1135
+ #: ../../library/dataclasses.rst:766
1132
1136
#, fuzzy
1133
1137
msgid ""
1134
1138
"Instead of looking for and disallowing objects of type :class:`list`, :class:"
@@ -1138,20 +1142,20 @@ msgstr ""
1138
1142
"不再查找和禁止型別為 :class:`list`、:class:`dict` 或 :class:`set` 的物件,現"
1139
1143
"在不允許使用不可散列的對像作為預設值。不可散列性用於近似可變性。"
1140
1144
1141
- #: ../../library/dataclasses.rst:770
1145
+ #: ../../library/dataclasses.rst:773
1142
1146
#, fuzzy
1143
1147
msgid "Descriptor-typed fields"
1144
1148
msgstr "描述器型別的欄位"
1145
1149
1146
- #: ../../library/dataclasses.rst:772
1150
+ #: ../../library/dataclasses.rst:775
1147
1151
#, fuzzy
1148
1152
msgid ""
1149
1153
"Fields that are assigned :ref:`descriptor objects <descriptors>` as their "
1150
1154
"default value have the following special behaviors:"
1151
1155
msgstr ""
1152
1156
"指定為\\ :ref:`描述器物件 <descriptors>`\\ 作為預設值的欄位具有以下特殊行為:"
1153
1157
1154
- #: ../../library/dataclasses.rst:775
1158
+ #: ../../library/dataclasses.rst:778
1155
1159
#, fuzzy
1156
1160
msgid ""
1157
1161
"The value for the field passed to the dataclass's :meth:`~object.__init__` "
@@ -1161,7 +1165,7 @@ msgstr ""
1161
1165
"傳遞給資料類別的 :meth:`~object.__init__` 方法的欄位值被傳遞給描述器的 :meth:"
1162
1166
"`~object.__set__` 方法,而不是覆蓋描述器物件。"
1163
1167
1164
- #: ../../library/dataclasses.rst:779
1168
+ #: ../../library/dataclasses.rst:782
1165
1169
#, fuzzy
1166
1170
msgid ""
1167
1171
"Similarly, when getting or setting the field, the descriptor's :meth:"
@@ -1171,7 +1175,7 @@ msgstr ""
1171
1175
"同樣,在獲取或設定欄位時,將呼叫描述器的 :meth:`~object.__get__` 或 :meth:`!"
1172
1176
"__set__` 方法,而不是回傳或覆蓋描述器物件。"
1173
1177
1174
- #: ../../library/dataclasses.rst:783
1178
+ #: ../../library/dataclasses.rst:786
1175
1179
#, fuzzy
1176
1180
msgid ""
1177
1181
"To determine whether a field contains a default value, :func:`@dataclass "
@@ -1187,7 +1191,7 @@ msgstr ""
1187
1191
"面,如果描述器在這種情況下引發 :exc:`AttributeError`,則不會為該欄位提供預設"
1188
1192
"值。"
1189
1193
1190
- #: ../../library/dataclasses.rst:818
1194
+ #: ../../library/dataclasses.rst:821
1191
1195
#, fuzzy
1192
1196
msgid ""
1193
1197
"Note that if a field is annotated with a descriptor type, but is not "
0 commit comments