-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathdataclasses.po
More file actions
880 lines (718 loc) · 80.9 KB
/
Copy pathdataclasses.po
File metadata and controls
880 lines (718 loc) · 80.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
# SOME DESCRIPTIVE TITLE.
# Copyright (C) 2001 Python Software Foundation
# This file is distributed under the same license as the Python package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
# Translators:
# Alireza Shabani (Revisto) <theRevisto@gmail.com>, 2025
# Rafael Fontenelle <rffontenelle@gmail.com>, 2025
# Sepehr Rasouli <sepehrrasouli06@gmail.com>, 2026
#
msgid ""
msgstr ""
"Project-Id-Version: Python 3.14\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2026-09-16 12:56+0000\n"
"PO-Revision-Date: 2026-09-14 15:51+0330\n"
"Last-Translator: Sepehr Rasouli <sepehrrasouli06@gmail.com>, 2026\n"
"Language-Team: Persian (https://github.com/python/python-docs-fa/)\n"
"Language: fa\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
"X-Generator: Poedit 3.6\n"
msgid ":mod:`!dataclasses` --- Data Classes"
msgstr ":mod:`!dataclasses` --- کلاسهای داده"
msgid "**Source code:** :source:`Lib/dataclasses.py`"
msgstr "**کد منبع:** :source:`Lib/dataclasses.py`"
msgid "This module provides a decorator and functions for automatically adding generated :term:`special methods <special method>` such as :meth:`~object.__init__` and :meth:`~object.__repr__` to user-defined classes. It was originally described in :pep:`557`."
msgstr "این ماژول یک دکوراتور و توابعی را برای افزودن خودکار :term:`متدهای ویژه <special method>` تولیدشده مانند :meth:`~object.__init__` و :meth:`~object.__repr__` به کلاسهای تعریفشده توسط کاربر فراهم میکند. این ماژول در ابتدا در :pep:`557` توصیفشده است."
msgid "The member variables to use in these generated methods are defined using :pep:`526` type annotations. For example, this code::"
msgstr "متغیرهای عضوی که در این متدهای تولیدشده به کار میروند، با حاشیهنویسیهای نوع :pep:`526` تعریف میشوند. برای مثال، این کد::"
msgid ""
"from dataclasses import dataclass\n"
"\n"
"@dataclass\n"
"class InventoryItem:\n"
" \"\"\"Class for keeping track of an item in inventory.\"\"\"\n"
" name: str\n"
" unit_price: float\n"
" quantity_on_hand: int = 0\n"
"\n"
" def total_cost(self) -> float:\n"
" return self.unit_price * self.quantity_on_hand"
msgstr ""
"from dataclasses import dataclass\n"
"\n"
"@dataclass\n"
"class InventoryItem:\n"
" \"\"\"Class for keeping track of an item in inventory.\"\"\"\n"
" name: str\n"
" unit_price: float\n"
" quantity_on_hand: int = 0\n"
"\n"
" def total_cost(self) -> float:\n"
" return self.unit_price * self.quantity_on_hand"
msgid "will add, among other things, a :meth:`!__init__` that looks like::"
msgstr "خواهد افزود، از جمله موارد دیگر، یک :meth:`!__init__` که به شکل زیر است::"
msgid ""
"def __init__(self, name: str, unit_price: float, quantity_on_hand: int = 0):\n"
" self.name = name\n"
" self.unit_price = unit_price\n"
" self.quantity_on_hand = quantity_on_hand"
msgstr ""
"def __init__(self, name: str, unit_price: float, quantity_on_hand: int = 0):\n"
" self.name = name\n"
" self.unit_price = unit_price\n"
" self.quantity_on_hand = quantity_on_hand"
msgid "Note that this method is automatically added to the class: it is not directly specified in the :class:`!InventoryItem` definition shown above."
msgstr "توجه داشته باشید که این متد بهطور خودکار به کلاس افزوده میشود: این متد بهطور مستقیم در تعریف :class:`!InventoryItem` که در بالا نشان داده شده است، مشخص نشده است."
msgid "Module contents"
msgstr "محتوای ماژول"
msgid "This function is a :term:`decorator` that is used to add generated :term:`special methods <special method>` to classes, as described below."
msgstr "این تابع یک :term:`دکوراتور <decorator>` است که برای افزودن :term:`متدهای ویژه <special method>` تولیدشده به کلاسها به کار میرود، همانطور که در ادامه توضیح داده شده است."
msgid "The ``@dataclass`` decorator examines the class to find ``field``\\s. A ``field`` is defined as a class variable that has a :term:`type annotation <variable annotation>`. With two exceptions described below, nothing in ``@dataclass`` examines the type specified in the variable annotation."
msgstr "دکوراتور ``@dataclass`` کلاس را بررسی میکند تا ``field``\\ها را پیدا کند. یک ``field`` بهعنوان متغیر کلاس تعریف میشود که دارای یک :term:`حاشیهنویسی نوع <variable annotation>` است. بهجز دو استثنا که در زیر توضیح داده شدهاند، هیچ چیزی در ``@dataclass`` نوع مشخصشده در حاشیهنویسی متغیر را بررسی نمیکند."
msgid "The order of the fields in all of the generated methods is the order in which they appear in the class definition."
msgstr "ترتیب فیلدها در تمام متدهای تولیدشده، همان ترتیبی است که در تعریف کلاس دارند."
msgid "The ``@dataclass`` decorator will add various \"dunder\" methods to the class, described below. If any of the added methods already exist in the class, the behavior depends on the parameter, as documented below. The decorator returns the same class that it is called on; no new class is created."
msgstr "دکوراتور ``@dataclass`` متدهای مختلف دو-زیرخطی (dunder) را به کلاس میافزاید که در زیر توضیح داده شدهاند. اگر هر یک از متدهای افزودهشده از قبل در کلاس وجود داشته باشند، رفتار به پارامتر بستگی دارد، همانطور که در زیر مستند شده است. دکوراتور همان کلاسی را که روی آن فراخوانیشده است برمیگرداند؛ هیچ کلاس جدیدی ایجاد نمیشود."
msgid "If ``@dataclass`` is used just as a simple decorator with no parameters, it acts as if it has the default values documented in this signature. That is, these three uses of ``@dataclass`` are equivalent::"
msgstr "اگر ``@dataclass`` فقط بهعنوان یک دکوراتور ساده بدون پارامتر استفاده شود، بهگونهای عمل میکند که گویی مقادیر پیشفرض مستندشده در این امضا را دارد. یعنی این سه کاربرد ``@dataclass`` معادلاند::"
msgid ""
"@dataclass\n"
"class C:\n"
" ...\n"
"\n"
"@dataclass()\n"
"class C:\n"
" ...\n"
"\n"
"@dataclass(init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False,\n"
" match_args=True, kw_only=False, slots=False, weakref_slot=False)\n"
"class C:\n"
" ..."
msgstr ""
"@dataclass\n"
"class C:\n"
" ...\n"
"\n"
"@dataclass()\n"
"class C:\n"
" ...\n"
"\n"
"@dataclass(init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False,\n"
" match_args=True, kw_only=False, slots=False, weakref_slot=False)\n"
"class C:\n"
" ..."
msgid "The parameters to ``@dataclass`` are:"
msgstr "پارامترهای ``@dataclass`` عبارتند از:"
msgid "*init*: If true (the default), a :meth:`~object.__init__` method will be generated."
msgstr "*init*: اگر درست باشد (پیشفرض)، یک متد :meth:`~object.__init__` تولید خواهد شد."
msgid "If the class already defines :meth:`!__init__`, this parameter is ignored."
msgstr "اگر کلاس از قبل :meth:`!__init__` را تعریف کرده باشد، این پارامتر نادیده گرفته میشود."
msgid "*repr*: If true (the default), a :meth:`~object.__repr__` method will be generated. The generated repr string will have the class name and the name and repr of each field, in the order they are defined in the class. Fields that are marked as being excluded from the repr are not included. For example: ``InventoryItem(name='widget', unit_price=3.0, quantity_on_hand=10)``."
msgstr "*repr*: اگر true باشد (پیشفرض)، یک متد :meth:`~object.__repr__` تولید خواهد شد. رشتهی repr تولیدشده، نام کلاس و نام و repr هر فیلد را به ترتیبی که در کلاس تعریف شدهاند، خواهد داشت. فیلدهایی که برای حذف از repr علامتگذاری شده باشند، گنجانده نمیشوند. برای مثال: ``InventoryItem(name='widget', unit_price=3.0, quantity_on_hand=10)``."
msgid "If the class already defines :meth:`!__repr__`, this parameter is ignored."
msgstr "اگر کلاس از قبل :meth:`!__repr__` را تعریف کرده باشد، این پارامتر نادیده گرفته میشود."
msgid "*eq*: If true (the default), an :meth:`~object.__eq__` method will be generated."
msgstr "*eq*: اگر true باشد (پیشفرض)، یک متد :meth:`~object.__eq__` تولید خواهد شد."
msgid "This method compares the class by comparing each field in order. Both instances in the comparison must be of the identical type."
msgstr "این متد، کلاس را با مقایسهی هر فیلد بهترتیب مقایسه میکند. هر دو نمونه در مقایسه باید از نوع یکسان باشند."
msgid "If the class already defines :meth:`!__eq__`, this parameter is ignored."
msgstr "اگر کلاس از قبل :meth:`!__eq__` را تعریف کرده باشد، این پارامتر نادیده گرفته میشود."
msgid "The generated ``__eq__`` method now compares each field individually (for example, ``self.a == other.a and self.b == other.b``), rather than comparing tuples of fields as in previous versions."
msgstr "متد ``__eq__`` تولیدشده اکنون هر فیلد را بهصورت جداگانه مقایسه میکند (برای مثال، ``self.a == other.a and self.b == other.b``)، نه اینکه مانند نسخههای پیشین تاپلهای فیلدها را مقایسه کند."
msgid "This change makes the comparison faster but it may alter results in cases where attributes compare equal by identity but not by value (such as ``float('nan')``)."
msgstr "این تغییر، مقایسه را سریعتر میکند، اما ممکن است نتایج را در مواردی که ویژگیها از نظر هویت برابر هستند ولی از نظر مقدار برابر نیستند (مانند ``float('nan')``) تغییر دهد."
msgid "In Python 3.12 and earlier, the comparison was performed by creating tuples of the fields and comparing them (for example, ``(self.a, self.b) == (other.a, other.b)``)."
msgstr "در پایتون 3.12 و نسخههای پیشین، مقایسه با ایجاد تاپلهایی از فیلدها و مقایسهی آنها انجام میشد (برای مثال، ``(self.a, self.b) == (other.a, other.b)``)."
msgid "*order*: If true (the default is ``False``), :meth:`~object.__lt__`, :meth:`~object.__le__`, :meth:`~object.__gt__`, and :meth:`~object.__ge__` methods will be generated. These compare the class as if it were a tuple of its fields, in order. Both instances in the comparison must be of the identical type. If *order* is true and *eq* is false, a :exc:`ValueError` is raised."
msgstr "*order*: اگر درست باشد (پیشفرض ``False`` است)، متدهای :meth:`~object.__lt__`، :meth:`~object.__le__`، :meth:`~object.__gt__` و :meth:`~object.__ge__` تولید میشوند. این متدها کلاس را بهگونهای مقایسه میکنند که گویی یک تاپل از فیلدهای آن بهترتیب است. هر دو نمونه در مقایسه باید از نوع یکسان باشند. اگر *order* درست باشد و *eq* نادرست باشد، یک :exc:`ValueError` پرتاب میشود."
msgid "If the class already defines any of :meth:`!__lt__`, :meth:`!__le__`, :meth:`!__gt__`, or :meth:`!__ge__`, then :exc:`TypeError` is raised."
msgstr "اگر کلاس از قبل هر یک از :meth:`!__lt__`، :meth:`!__le__`، :meth:`!__gt__`، یا :meth:`!__ge__` را تعریف کرده باشد، :exc:`TypeError` پرتاب میشود."
msgid "*unsafe_hash*: If true, force ``dataclasses`` to create a :meth:`~object.__hash__` method, even though it may not be safe to do so. Otherwise, generate a :meth:`~object.__hash__` method according to how *eq* and *frozen* are set. The default value is ``False``."
msgstr "*unsafe_hash*: اگر true باشد، ``dataclasses`` را وادار به ایجاد یک متد :meth:`~object.__hash__` میکند، هرچند ممکن است این کار امن نباشد. در غیر این صورت، یک متد :meth:`~object.__hash__` با توجه به نحوهی تنظیم *eq* و *frozen* تولید میشود. مقدار پیشفرض ``False`` است."
msgid ":meth:`!__hash__` is used by built-in :meth:`hash`, and when objects are added to hashed collections such as dictionaries and sets. Having a :meth:`!__hash__` implies that instances of the class are immutable. Mutability is a complicated property that depends on the programmer's intent, the existence and behavior of :meth:`!__eq__`, and the values of the *eq* and *frozen* flags in the ``@dataclass`` decorator."
msgstr ":meth:`!__hash__` توسط :meth:`hash` توکار، و هنگام اضافه شدن شیءها به مجموعههای هششده مانند دیکشنریها و مجموعهها استفاده میشود. وجود :meth:`!__hash__` به این معناست که نمونههای کلاس تغییرناپذیر هستند. تغییرپذیری ویژگی پیچیدهای است که به قصد برنامهنویس، وجود و رفتار :meth:`!__eq__`، و مقادیر پرچمهای *eq* و *frozen* در دکوراتور ``@dataclass`` بستگی دارد."
msgid "By default, ``@dataclass`` will not implicitly add a :meth:`~object.__hash__` method unless it is safe to do so. Neither will it add or change an existing explicitly defined :meth:`!__hash__` method. Setting the class attribute ``__hash__ = None`` has a specific meaning to Python, as described in the :meth:`!__hash__` documentation."
msgstr "بهطور پیشفرض، ``@dataclass`` متد :meth:`~object.__hash__` را بهصورت ضمنی اضافه نمیکند، مگر اینکه انجام این کار امن باشد. همچنین متد :meth:`!__hash__` موجودی را که بهصورت صریح تعریفشده است، اضافه یا تغییر نمیدهد. تنظیم ویژگی کلاس ``__hash__ = None`` برای پایتون معنای مشخصی دارد، همانطور که در مستندات :meth:`!__hash__` آمده است."
msgid "If :meth:`!__hash__` is not explicitly defined, or if it is set to ``None``, then ``@dataclass`` *may* add an implicit :meth:`!__hash__` method. Although not recommended, you can force ``@dataclass`` to create a :meth:`!__hash__` method with ``unsafe_hash=True``. This might be the case if your class is logically immutable but can still be mutated. This is a specialized use case and should be considered carefully."
msgstr "اگر :meth:`!__hash__` بهصراحت تعریف نشده باشد، یا اگر روی ``None`` تنظیم شده باشد، آنگاه ``@dataclass`` *ممکن است* یک متد :meth:`!__hash__` ضمنی اضافه کند. اگرچه توصیه نمیشود، اما میتوانید ``@dataclass`` را وادار کنید تا یک متد :meth:`!__hash__` را با ``unsafe_hash=True`` ایجاد کند. این حالت ممکن است زمانی رخ دهد که کلاس شما از نظر منطقی تغییرناپذیر است اما همچنان میتواند تغییر یابد. این یک مورد استفاده تخصصی است و باید با دقت در نظر گرفته شود."
msgid "Here are the rules governing implicit creation of a :meth:`!__hash__` method. Note that you cannot both have an explicit :meth:`!__hash__` method in your dataclass and set ``unsafe_hash=True``; this will result in a :exc:`TypeError`."
msgstr "در ادامه، قواعد حاکم بر ایجاد ضمنی یک متد :meth:`!__hash__` آمده است. توجه داشته باشید که نمیتوانید همزمان یک متد :meth:`!__hash__` صریح در دیتاکلاس خود داشته باشید و ``unsafe_hash=True`` را تنظیم کنید؛ این کار منجر به :exc:`TypeError` میشود."
msgid "If *eq* and *frozen* are both true, by default ``@dataclass`` will generate a :meth:`!__hash__` method for you. If *eq* is true and *frozen* is false, :meth:`!__hash__` will be set to ``None``, marking it unhashable (which it is, since it is mutable). If *eq* is false, :meth:`!__hash__` will be left untouched meaning the :meth:`!__hash__` method of the superclass will be used (if the superclass is :class:`object`, this means it will fall back to id-based hashing)."
msgstr "اگر *eq* و *frozen* هر دو درست باشند، بهطور پیشفرض ``@dataclass`` یک متد :meth:`!__hash__` برای شما تولید خواهد کرد. اگر *eq* درست باشد و *frozen* نادرست باشد، :meth:`!__hash__` روی ``None`` تنظیم خواهد شد، که آن را بهعنوان هشناپذیر (unhashable) علامتگذاری میکند (که همینطور است، زیرا تغییرپذیر است). اگر *eq* نادرست باشد، :meth:`!__hash__` دستنخورده باقی خواهد ماند، به این معنا که متد :meth:`!__hash__` ابرکلاس استفاده خواهد شد (اگر ابرکلاس :class:`object` باشد، این بدان معناست که به هش مبتنی بر شناسه (id-based hashing) بازگشت خواهد شد)."
msgid "*frozen*: If true (the default is ``False``), assigning to fields will generate an exception. This emulates read-only frozen instances. See the :ref:`discussion <dataclasses-frozen>` below."
msgstr "*frozen*: اگر true باشد (پیشفرض ``False`` است)، انتساب به فیلدها باعث ایجاد یک استثنا میشود. این حالت، نمونههای فریزشده فقطخواندنی را شبیهسازی میکند. به :ref:`بحث <dataclasses-frozen>` در زیر مراجعه کنید."
msgid "If :meth:`~object.__setattr__` or :meth:`~object.__delattr__` is defined in the class and *frozen* is true, then :exc:`TypeError` is raised."
msgstr "اگر :meth:`~object.__setattr__` یا :meth:`~object.__delattr__` در کلاس تعریف شده باشد و *frozen* برابر true باشد، :exc:`TypeError` پرتاب میشود."
msgid "*match_args*: If true (the default is ``True``), the :attr:`~object.__match_args__` tuple will be created from the list of non keyword-only parameters to the generated :meth:`~object.__init__` method (even if :meth:`!__init__` is not generated, see above). If false, or if :attr:`!__match_args__` is already defined in the class, then :attr:`!__match_args__` will not be generated."
msgstr "*match_args*: اگر درست باشد (پیشفرض ``True`` است)، تاپل :attr:`~object.__match_args__` از فهرست پارامترهای متد تولیدشدهی :meth:`~object.__init__` که فقطکلیدواژهای نیستند ایجاد میشود (حتی اگر :meth:`!__init__` تولید نشده باشد، بالا را ببینید). اگر نادرست باشد، یا اگر :attr:`!__match_args__` از قبل در کلاس تعریف شده باشد، :attr:`!__match_args__` تولید نخواهد شد."
msgid "*kw_only*: If true (the default value is ``False``), then all fields will be marked as keyword-only. If a field is marked as keyword-only, then the only effect is that the :meth:`~object.__init__` parameter generated from a keyword-only field must be specified with a keyword when :meth:`!__init__` is called. See the :term:`parameter` glossary entry for details. Also see the :const:`KW_ONLY` section."
msgstr "*kw_only*: اگر درست باشد (مقدار پیشفرض ``False`` است)، تمام فیلدها بهعنوان فقط کلیدواژهای علامتگذاری میشوند. اگر فیلدی بهعنوان فقط کلیدواژهای علامتگذاری شده باشد، تنها اثر آن این است که پارامتر :meth:`~object.__init__` که از یک فیلد فقط کلیدواژهای تولید شده است، باید هنگام فراخوانی :meth:`!__init__` با یک کلیدواژه مشخص شود. برای جزئیات، مدخل :term:`پارامتر <parameter>` در واژهنامه را ببینید. همچنین بخش :const:`KW_ONLY` را ببینید."
msgid "Keyword-only fields are not included in :attr:`!__match_args__`."
msgstr "فیلدهای فقطکلیدواژهای در :attr:`!__match_args__` گنجانده نمیشوند."
msgid "*slots*: If true (the default is ``False``), :attr:`~object.__slots__` attribute will be generated and new class will be returned instead of the original one. If :attr:`!__slots__` is already defined in the class, then :exc:`TypeError` is raised."
msgstr "*slots*: اگر درست باشد (پیشفرض ``False`` است)، ویژگی :attr:`~object.__slots__` ایجاد میشود و کلاس جدید به جای کلاس اصلی برگردانده میشود. اگر :attr:`!__slots__` از قبل در کلاس تعریف شده باشد، :exc:`TypeError` پرتاب میشود."
msgid "Passing parameters to a base class :meth:`~object.__init_subclass__` when using ``slots=True`` will result in a :exc:`TypeError`. Either use ``__init_subclass__`` with no parameters or use default values as a workaround. See :gh:`91126` for full details."
msgstr "ارسال پارامترها به :meth:`~object.__init_subclass__` کلاس پایه، هنگام استفاده از ``slots=True``، به :exc:`TypeError` منجر میشود. یا از ``__init_subclass__`` بدون پارامتر استفاده کنید یا از مقادیر پیشفرض بهعنوان راهحل موقت استفاده کنید. برای جزئیات کامل، :gh:`91126` را ببینید."
msgid "If a field name is already included in the :attr:`!__slots__` of a base class, it will not be included in the generated :attr:`!__slots__` to prevent :ref:`overriding them <datamodel-note-slots>`. Therefore, do not use :attr:`!__slots__` to retrieve the field names of a dataclass. Use :func:`fields` instead. To be able to determine inherited slots, base class :attr:`!__slots__` may be any iterable, but *not* an iterator."
msgstr "اگر نام فیلدی از قبل در :attr:`!__slots__` یک کلاس پایه گنجانده شده باشد، برای جلوگیری از :ref:`بازنویسی آنها <datamodel-note-slots>`، در :attr:`!__slots__` تولیدشده گنجانده نخواهد شد. بنابراین، برای بازیابی نام فیلدهای یک دیتاکلاس از :attr:`!__slots__` استفاده نکنید. در عوض از :func:`fields` استفاده کنید. برای این که بتوان جایگاههای ارثبریشده را تعیین کرد، :attr:`!__slots__` کلاس پایه میتواند هر پیمایشپذیری باشد، اما *نه* یک پیمایشگر ."
msgid "*weakref_slot*: If true (the default is ``False``), add a slot named \"__weakref__\", which is required to make an instance :func:`weakref-able <weakref.ref>`. It is an error to specify ``weakref_slot=True`` without also specifying ``slots=True``."
msgstr "*weakref_slot*: اگر درست باشد (پیشفرض ``False`` است)، یک جایگاه به نام \"__weakref__\" افزوده میشود، که برای :func:`weakref-able <weakref.ref>` کردن یک نمونه لازم است. تعیین ``weakref_slot=True`` بدون اینکه ``slots=True`` نیز تعیین شود، خطا است."
msgid "``field``\\s may optionally specify a default value, using normal Python syntax::"
msgstr "``field``\\s میتوانند بهاختیار یک مقدار پیشفرض را با استفاده از سینتکس عادی پایتون مشخص کنند::"
msgid ""
"@dataclass\n"
"class C:\n"
" a: int # 'a' has no default value\n"
" b: int = 0 # assign a default value for 'b'"
msgstr ""
"@dataclass\n"
"class C:\n"
" a: int # 'a' has no default value\n"
" b: int = 0 # assign a default value for 'b'"
msgid "In this example, both :attr:`!a` and :attr:`!b` will be included in the added :meth:`~object.__init__` method, which will be defined as::"
msgstr "در این مثال، هر دو :attr:`!a` و :attr:`!b` در متد :meth:`~object.__init__` افزودهشده گنجانده خواهند شد، که بهصورت زیر تعریف خواهد شد::"
msgid "def __init__(self, a: int, b: int = 0):"
msgstr "def __init__(self, a: int, b: int = 0):"
msgid ":exc:`TypeError` will be raised if a field without a default value follows a field with a default value. This is true whether this occurs in a single class, or as a result of class inheritance."
msgstr "اگر یک فیلد بدون مقدار پیشفرض پس از یک فیلد دارای مقدار پیشفرض قرار بگیرد، :exc:`TypeError` پرتاب خواهد شد. این موضوع چه در یک کلاس واحد رخ دهد و چه در نتیجه وراثت کلاس، صادق است."
msgid "For common and simple use cases, no other functionality is required. There are, however, some dataclass features that require additional per-field information. To satisfy this need for additional information, you can replace the default field value with a call to the provided :func:`!field` function. For example::"
msgstr "برای موارد استفادهی رایج و ساده، به قابلیت دیگری نیاز نیست. با این حال، برخی از قابلیتهای دیتاکلاس به اطلاعات اضافی بهازای هر فیلد نیاز دارند. برای برآورده کردن این نیاز به اطلاعات اضافی، میتوانید مقدار پیشفرض فیلد را با فراخوانی تابع ارائهشده :func:`!field` جایگزین کنید. برای مثال::"
msgid ""
"@dataclass\n"
"class C:\n"
" mylist: list[int] = field(default_factory=list)\n"
"\n"
"c = C()\n"
"c.mylist += [1, 2, 3]"
msgstr ""
"@dataclass\n"
"class C:\n"
" mylist: list[int] = field(default_factory=list)\n"
"\n"
"c = C()\n"
"c.mylist += [1, 2, 3]"
msgid "As shown above, the :const:`MISSING` value is a sentinel object used to detect if some parameters are provided by the user. This sentinel is used because ``None`` is a valid value for some parameters with a distinct meaning. No code should directly use the :const:`MISSING` value."
msgstr "همانطور که در بالا نشان داده شد، مقدار :const:`MISSING` یک شیء نشانگر (sentinel) است که برای تشخیص اینکه آیا برخی پارامترها توسط کاربر ارائه شدهاند، استفاده میشود. این نشانگر به این دلیل استفاده میشود که ``None`` برای برخی پارامترها یک مقدار معتبر با معنایی متمایز است. هیچ کدی نباید بهطور مستقیم از مقدار :const:`MISSING` استفاده کند."
msgid "The parameters to :func:`!field` are:"
msgstr "پارامترهای :func:`!field` عبارتند از:"
msgid "*default*: If provided, this will be the default value for this field. This is needed because the :func:`!field` call itself replaces the normal position of the default value."
msgstr "*default*: اگر ارائه شود، این، مقدار پیشفرض این فیلد خواهد بود. این امر لازم است، زیرا فراخوانی :func:`!field` بهخودیخود جایگزین جایگاه عادی مقدار پیشفرض میشود."
msgid "*default_factory*: If provided, it must be a zero-argument callable that will be called when a default value is needed for this field. Among other purposes, this can be used to specify fields with mutable default values, as discussed below. It is an error to specify both *default* and *default_factory*."
msgstr "*default_factory*: در صورت ارائه، باید یک شیء فراخوانیپذیر بدون آرگومان باشد که هنگام نیاز به یک مقدار پیشفرض برای این فیلد فراخوانی میشود. از جمله کاربردهای دیگر، میتوان از آن برای مشخص کردن فیلدهایی با مقادیر پیشفرض تغییرپذیر استفاده کرد، همانطور که در ادامه بحث شده است. مشخص کردن هر دو *default* و *default_factory* خطا است."
msgid "*init*: If true (the default), this field is included as a parameter to the generated :meth:`~object.__init__` method."
msgstr "*init*: اگر true باشد (پیشفرض)، این فیلد بهعنوان پارامتری به متد تولیدشدهی :meth:`~object.__init__` اضافه میشود."
msgid "*repr*: If true (the default), this field is included in the string returned by the generated :meth:`~object.__repr__` method."
msgstr "*repr*: اگر true باشد (پیشفرض)، این فیلد در رشتهی برگرداندهشده توسط متد تولیدشدهی :meth:`~object.__repr__` گنجانده میشود."
msgid "*hash*: This can be a bool or ``None``. If true, this field is included in the generated :meth:`~object.__hash__` method. If false, this field is excluded from the generated :meth:`~object.__hash__`. If ``None`` (the default), use the value of *compare*: this would normally be the expected behavior, since a field should be included in the hash if it's used for comparisons. Setting this value to anything other than ``None`` is discouraged."
msgstr "*hash*: این مقدار میتواند یک بولی یا ``None`` باشد. اگر True باشد، این فیلد در متد :meth:`~object.__hash__` که تولید میشود گنجانده میشود. اگر False باشد، این فیلد از متد :meth:`~object.__hash__` که تولید میشود حذف میشود. اگر ``None`` (پیشفرض) باشد، از مقدار *compare* استفاده میشود: این معمولاً رفتار مورد انتظار است، زیرا اگر از فیلدی برای مقایسهها استفاده شود، باید آن فیلد در هش گنجانده شود. تنظیم این مقدار به مقداری غیر از ``None`` توصیه نمیشود."
msgid "One possible reason to set ``hash=False`` but ``compare=True`` would be if a field is expensive to compute a hash value for, that field is needed for equality testing, and there are other fields that contribute to the type's hash value. Even if a field is excluded from the hash, it will still be used for comparisons."
msgstr "یکی از دلایل ممکن برای تنظیم ``hash=False`` اما ``compare=True`` میتواند این باشد که محاسبهی مقدار هش برای یک فیلد پرهزینه باشد، آن فیلد برای آزمون برابری لازم باشد و فیلدهای دیگری وجود داشته باشند که در مقدار هشِ نوع نقش دارند. حتی اگر یک فیلد از هش حذف شده باشد، همچنان برای مقایسهها استفاده خواهد شد."
msgid "*compare*: If true (the default), this field is included in the generated equality and comparison methods (:meth:`~object.__eq__`, :meth:`~object.__gt__`, et al.)."
msgstr "*compare*: اگر true باشد (پیشفرض)، این فیلد در متدهای تولیدشدهی برابری و مقایسه (:meth:`~object.__eq__`، :meth:`~object.__gt__` و غیره) گنجانده میشود."
msgid "*metadata*: This can be a mapping or ``None``. ``None`` is treated as an empty dict. This value is wrapped in :func:`~types.MappingProxyType` to make it read-only, and exposed on the :class:`Field` object. It is not used at all by Data Classes, and is provided as a third-party extension mechanism. Multiple third-parties can each have their own key, to use as a namespace in the metadata."
msgstr "*metadata*: این مقدار میتواند یک نگاشت یا ``None`` باشد. با ``None`` بهعنوان یک دیکشنری خالی رفتار میشود. این مقدار در :func:`~types.MappingProxyType` قرار میگیرد تا فقطخواندنی شود، و بر روی شیء :class:`Field` نمایان میشود. این مقدار بههیچوجه توسط Data Classes استفاده نمیشود، و بهعنوان سازوکاری برای توسعه توسط شخص ثالث ارائه شده است. چندین شخص ثالث میتوانند هرکدام کلید خودشان را داشته باشند تا از آن بهعنوان فضای نام در metadata استفاده کنند."
msgid "*kw_only*: If true, this field will be marked as keyword-only. This is used when the generated :meth:`~object.__init__` method's parameters are computed."
msgstr "*kw_only*: اگر true باشد، این فیلد بهعنوان فقط کلیدواژهای علامتگذاری میشود. این موضوع زمانی استفاده میشود که پارامترهای متدِ تولیدشدهی :meth:`~object.__init__` محاسبه میشوند."
msgid "Keyword-only fields are also not included in :attr:`!__match_args__`."
msgstr "فیلدهای فقط کلیدواژهای نیز در :attr:`!__match_args__` گنجانده نمیشوند."
msgid "*doc*: optional docstring for this field."
msgstr "*doc*: رشتهی مستندسازی اختیاری برای این فیلد."
msgid "If the default value of a field is specified by a call to :func:`!field`, then the class attribute for this field will be replaced by the specified *default* value. If *default* is not provided, then the class attribute will be deleted. The intent is that after the :deco:`dataclass` decorator runs, the class attributes will all contain the default values for the fields, just as if the default value itself were specified. For example, after::"
msgstr "اگر مقدار پیشفرض یک فیلد با فراخوانی :func:`!field` مشخص شده باشد، آنگاه صفت کلاس مربوط به این فیلد با مقدار *default* مشخصشده جایگزین میشود. اگر *default* ارائه نشده باشد، آنگاه صفت کلاس حذف میشود. هدف این است که پس از اجرای دکوراتور :deco:`dataclass`، صفات کلاس همگی حاوی مقادیر پیشفرض فیلدها خواهند بود، درست همانگونه که اگر خود مقدار پیشفرض مشخص شده باشد. برای مثال، پس از::"
msgid ""
"@dataclass\n"
"class C:\n"
" x: int\n"
" y: int = field(repr=False)\n"
" z: int = field(repr=False, default=10)\n"
" t: int = 20"
msgstr ""
"@dataclass\n"
"class C:\n"
" x: int\n"
" y: int = field(repr=False)\n"
" z: int = field(repr=False, default=10)\n"
" t: int = 20"
msgid "The class attribute :attr:`!C.z` will be ``10``, the class attribute :attr:`!C.t` will be ``20``, and the class attributes :attr:`!C.x` and :attr:`!C.y` will not be set."
msgstr "صفت کلاس :attr:`!C.z` برابر ``10`` خواهد بود، صفت کلاس :attr:`!C.t` برابر ``20`` خواهد بود، و صفات کلاس :attr:`!C.x` و :attr:`!C.y` تنظیم نخواهند شد."
msgid ":class:`!Field` objects describe each defined field. These objects are created internally, and are returned by the :func:`fields` module-level method (see below). Users should never instantiate a :class:`!Field` object directly. Its documented attributes are:"
msgstr "اشیای :class:`!Field` هر فیلد تعریفشده را توصیف میکنند. این اشیاء بهصورت داخلی ایجاد میشوند و توسط متد :func:`fields` در سطح ماژول برگردانده میشوند (در زیر ببینید). کاربران هرگز نباید یک شیء :class:`!Field` را مستقیماً نمونهسازی کنند. ویژگیهای مستندشدهی آن عبارتاند از:"
msgid ":attr:`!name`: The name of the field."
msgstr ":attr:`!name`: نام فیلد."
msgid ":attr:`!type`: The type of the field."
msgstr ":attr:`!type`: نوع فیلد."
msgid ":attr:`!default`, :attr:`!default_factory`, :attr:`!init`, :attr:`!repr`, :attr:`!hash`, :attr:`!compare`, :attr:`!metadata`, and :attr:`!kw_only` have the identical meaning and values as they do in the :func:`field` function."
msgstr ":attr:`!default`، :attr:`!default_factory`، :attr:`!init`، :attr:`!repr`، :attr:`!hash`، :attr:`!compare`، :attr:`!metadata` و :attr:`!kw_only` دقیقاً همان معنا و مقادیری را دارند که در تابع :func:`field` دارند."
msgid "Other attributes may exist, but they are private and must not be inspected or relied on."
msgstr "ممکن است ویژگیهای دیگری نیز وجود داشته باشند، اما آنها خصوصی هستند و نباید بررسی شوند یا به آنها اتکا شود."
msgid "``InitVar[T]`` type annotations describe variables that are :ref:`init-only <dataclasses-init-only-variables>`. Fields annotated with :class:`!InitVar` are considered pseudo-fields, and thus are neither returned by the :func:`fields` function nor used in any way except adding them as parameters to :meth:`~object.__init__` and an optional :meth:`__post_init__`."
msgstr "حاشیهنویسیهای نوع ``InitVar[T]`` متغیرهایی را توصیف میکنند که :ref:`فقط init <dataclasses-init-only-variables>` هستند. فیلدهایی که با :class:`!InitVar` حاشیهنویسی شدهاند، شبهفیلد محسوب میشوند، و بنابراین نه توسط تابع :func:`fields` برگردانده میشوند و نه به هیچ شکلی استفاده میشوند، مگر اینکه بهعنوان پارامتر به :meth:`~object.__init__` و یک :meth:`__post_init__` اختیاری اضافه شوند."
msgid "Returns a tuple of :class:`Field` objects that define the fields for this dataclass. Accepts either a dataclass, or an instance of a dataclass. Raises :exc:`TypeError` if not passed a dataclass or instance of one. Does not return pseudo-fields which are ``ClassVar`` or ``InitVar``."
msgstr "تاپلی از اشیای :class:`Field` برمیگرداند که فیلدهای این دیتاکلاس را تعریف میکنند. یک دیتاکلاس یا نمونهای از دیتاکلاس را میپذیرد. اگر دیتاکلاس یا نمونهای از آن پاس داده نشود، :exc:`TypeError` را پرتاب میکند. شبهفیلدهایی که ``ClassVar`` یا ``InitVar`` باشند را برنمیگرداند."
msgid "Converts the dataclass *obj* to a dict (by using the factory function *dict_factory*). Each dataclass is converted to a dict of its fields, as ``name: value`` pairs. dataclasses, dicts, lists, and tuples are recursed into. Other objects are copied with :func:`copy.deepcopy`."
msgstr "دیتاکلاس *obj* را به یک دیکشنری تبدیل میکند (با استفاده از تابع کارخانهای *dict_factory*). هر دیتاکلاس به دیکشنری از فیلدهای آن، بهصورت جفتهای ``name: value`` تبدیل میشود. دیتاکلاسها، دیکشنریها، فهرستها و تاپلها بهصورت بازگشتی پردازش میشوند. سایر اشیاء با :func:`copy.deepcopy` کپی میشوند."
msgid "Example of using :func:`!asdict` on nested dataclasses::"
msgstr "مثالی از استفاده از :func:`!asdict` روی دیتاکلاسهای تودرتو::"
msgid ""
"@dataclass\n"
"class Point:\n"
" x: int\n"
" y: int\n"
"\n"
"@dataclass\n"
"class C:\n"
" mylist: list[Point]\n"
"\n"
"p = Point(10, 20)\n"
"assert asdict(p) == {'x': 10, 'y': 20}\n"
"\n"
"c = C([Point(0, 0), Point(10, 4)])\n"
"assert asdict(c) == {'mylist': [{'x': 0, 'y': 0}, {'x': 10, 'y': 4}]}"
msgstr ""
"@dataclass\n"
"class Point:\n"
" x: int\n"
" y: int\n"
"\n"
"@dataclass\n"
"class C:\n"
" mylist: list[Point]\n"
"\n"
"p = Point(10, 20)\n"
"assert asdict(p) == {'x': 10, 'y': 20}\n"
"\n"
"c = C([Point(0, 0), Point(10, 4)])\n"
"assert asdict(c) == {'mylist': [{'x': 0, 'y': 0}, {'x': 10, 'y': 4}]}"
msgid "To create a shallow copy, the following workaround may be used::"
msgstr "برای ایجاد یک کپی سطحی، میتوان از راهحل جایگزین زیر استفاده کرد::"
msgid "{field.name: getattr(obj, field.name) for field in fields(obj)}"
msgstr "{field.name: getattr(obj, field.name) for field in fields(obj)}"
msgid ":func:`!asdict` raises :exc:`TypeError` if *obj* is not a dataclass instance."
msgstr ":func:`!asdict` در صورتی که *obj* نمونهای از دیتاکلاس نباشد، :exc:`TypeError` را پرتاب میکند."
msgid "Converts the dataclass *obj* to a tuple (by using the factory function *tuple_factory*). Each dataclass is converted to a tuple of its field values. dataclasses, dicts, lists, and tuples are recursed into. Other objects are copied with :func:`copy.deepcopy`."
msgstr "دیتاکلاس *obj* را به یک تاپل تبدیل میکند (با استفاده از تابع کارخانهای *tuple_factory*). هر دیتاکلاس به یک تاپل از مقادیر فیلدهای آن تبدیل میشود. دیتاکلاسها، دیکشنریها، فهرستها و تاپلها بهصورت بازگشتی پیمایش میشوند. سایر اشیاء با :func:`copy.deepcopy` کپی میشوند."
msgid "Continuing from the previous example::"
msgstr "در ادامه از مثال پیشین::"
msgid ""
"assert astuple(p) == (10, 20)\n"
"assert astuple(c) == ([(0, 0), (10, 4)],)"
msgstr ""
"assert astuple(p) == (10, 20)\n"
"assert astuple(c) == ([(0, 0), (10, 4)],)"
msgid "tuple(getattr(obj, field.name) for field in dataclasses.fields(obj))"
msgstr "tuple(getattr(obj, field.name) for field in dataclasses.fields(obj))"
msgid ":func:`!astuple` raises :exc:`TypeError` if *obj* is not a dataclass instance."
msgstr ":func:`!astuple` در صورتی که *obj* نمونهای از dataclass نباشد، :exc:`TypeError` را پرتاب میکند."
msgid "Creates a new dataclass with name *cls_name*, fields as defined in *fields*, base classes as given in *bases*, and initialized with a namespace as given in *namespace*. *fields* is an iterable whose elements are each either ``name``, ``(name, type)``, or ``(name, type, Field)``. If just ``name`` is supplied, :data:`typing.Any` is used for ``type``. The values of *init*, *repr*, *eq*, *order*, *unsafe_hash*, *frozen*, *match_args*, *kw_only*, *slots*, and *weakref_slot* have the same meaning as they do in :deco:`dataclass`."
msgstr "یک دیتاکلاس جدید با نام *cls_name*، فیلدهای تعریفشده در *fields*، کلاسهای پایه دادهشده در *bases* ایجاد میکند و آن را با فضای نام دادهشده در *namespace* مقداردهی اولیه میکند. *fields* یک پیمایشپذیر است که هر یک از عناصر آن یکی از ``name``، ``(name, type)`` یا ``(name, type, Field)`` است. اگر فقط ``name`` ارائه شود، برای ``type`` از :data:`typing.Any` استفاده میشود. مقادیر *init*، *repr*، *eq*، *order*، *unsafe_hash*، *frozen*، *match_args*، *kw_only*، *slots* و *weakref_slot* همان معنایی را دارند که در :deco:`dataclass` دارند."
msgid "If *module* is defined, the :attr:`!__module__` attribute of the dataclass is set to that value. By default, it is set to the module name of the caller."
msgstr "اگر *module* تعریفشده باشد، ویژگی :attr:`!__module__` دیتاکلاس به آن مقدار تنظیم میشود. بهطور پیشفرض، این ویژگی به نام ماژول فراخواننده تنظیم میشود."
msgid "The *decorator* parameter is a callable that will be used to create the dataclass. It should take the class object as a first argument and the same keyword arguments as :deco:`dataclass`. By default, the :deco:`dataclass` function is used."
msgstr "پارامتر *decorator* یک شیء فراخوانیپذیر است که برای ایجاد دیتاکلاس استفاده خواهد شد. این فراخوانیپذیر باید شیء کلاس را بهعنوان اولین آرگومان و همان آرگومانهای کلیدواژهایِ :deco:`dataclass` را نیز بپذیرد. بهطور پیشفرض، از تابع :deco:`dataclass` استفاده میشود."
msgid "This function is not strictly required, because any Python mechanism for creating a new class with :attr:`~object.__annotations__` can then apply the :deco:`dataclass` function to convert that class to a dataclass. This function is provided as a convenience. For example::"
msgstr "این تابع بهطور اکید الزامی نیست، زیرا هر سازوکار پایتون برای ایجاد یک کلاس جدید با :attr:`~object.__annotations__` میتواند سپس تابع :deco:`dataclass` را برای تبدیل آن کلاس به یک دیتاکلاس اعمال کند. این تابع برای سهولت ارائه شده است. برای مثال::"
msgid ""
"C = make_dataclass('C',\n"
" [('x', int),\n"
" 'y',\n"
" ('z', int, field(default=5))],\n"
" namespace={'add_one': lambda self: self.x + 1})"
msgstr ""
"C = make_dataclass('C',\n"
" [('x', int),\n"
" 'y',\n"
" ('z', int, field(default=5))],\n"
" namespace={'add_one': lambda self: self.x + 1})"
msgid "Is equivalent to::"
msgstr "معادل است با::"
msgid ""
"@dataclass\n"
"class C:\n"
" x: int\n"
" y: 'typing.Any'\n"
" z: int = 5\n"
"\n"
" def add_one(self):\n"
" return self.x + 1"
msgstr ""
"@dataclass\n"
"class C:\n"
" x: int\n"
" y: 'typing.Any'\n"
" z: int = 5\n"
"\n"
" def add_one(self):\n"
" return self.x + 1"
msgid "Added the *decorator* parameter."
msgstr "پارامتر *decorator* اضافه شد."
msgid "Creates a new object of the same type as *obj*, replacing fields with values from *changes*. If *obj* is not a Data Class, raises :exc:`TypeError`. If keys in *changes* are not field names of the given dataclass, raises :exc:`TypeError`."
msgstr "یک شیء جدید از همان نوع *obj* ایجاد میکند و فیلدها را با مقادیر *changes* جایگزین میکند. اگر *obj* یک دیتاکلاس نباشد، :exc:`TypeError` را پرتاب میکند. اگر کلیدهای موجود در *changes* نام فیلدهای دیتاکلاسشده نباشند، :exc:`TypeError` را پرتاب میکند."
msgid "The newly returned object is created by calling the :meth:`~object.__init__` method of the dataclass. This ensures that :meth:`__post_init__`, if present, is also called."
msgstr "شیء تازه بازگشتدادهشده با فراخوانی متد :meth:`~object.__init__` دیتاکلاس ایجاد میشود. این امر تضمین میکند که :meth:`__post_init__`، در صورت وجود، نیز فراخوانی شود."
msgid "Init-only variables without default values, if any exist, must be specified on the call to :func:`!replace` so that they can be passed to :meth:`!__init__` and :meth:`__post_init__`."
msgstr "متغیرهای فقط مقداردهی اولیه بدون مقدار پیشفرض، در صورت وجود، باید در فراخوانی :func:`!replace` مشخص شوند تا بتوان آنها را به :meth:`!__init__` و :meth:`__post_init__` ارسال کرد."
msgid "It is an error for *changes* to contain any fields that are defined as having ``init=False``. A :exc:`ValueError` will be raised in this case."
msgstr "وجود هر فیلدی در *changes* که با ``init=False`` تعریف شده باشد، خطا است. در این حالت یک :exc:`ValueError` پرتاب خواهد شد."
msgid "Be forewarned about how ``init=False`` fields work during a call to :func:`!replace`. They are not copied from the source object, but rather are initialized in :meth:`__post_init__`, if they're initialized at all. It is expected that ``init=False`` fields will be rarely and judiciously used. If they are used, it might be wise to have alternate class constructors, or perhaps a custom :func:`!replace` (or similarly named) method which handles instance copying."
msgstr "از پیش آگاه باشید که فیلدهای ``init=False`` در هنگام فراخوانی :func:`!replace` چگونه کار میکنند. آنها از شیء مبدأ کپی نمیشوند، بلکه در :meth:`__post_init__` مقداردهی اولیه میشوند، اگر اصلاً مقداردهی اولیه شوند. انتظار میرود فیلدهای ``init=False`` بهندرت و با تدبیر مورد استفاده قرار گیرند. اگر از آنها استفاده شود، شاید بهتر باشد سازندههای جایگزین کلاس یا شاید یک متد سفارشی :func:`!replace` (یا با نام مشابه) داشته باشید که کپی نمونه را مدیریت میکند."
msgid "Dataclass instances are also supported by generic function :func:`copy.replace`."
msgstr "تابع عام :func:`copy.replace` نیز از نمونههای دیتاکلاس پشتیبانی میکند."
msgid "Return ``True`` if its parameter is a dataclass (including subclasses of a dataclass, but not including :ref:`generic aliases <types-genericalias>`) or an instance of one, otherwise return ``False``."
msgstr "اگر پارامتر آن یک دیتاکلاس باشد (شامل زیرکلاسهای یک دیتاکلاس، اما نه شامل :ref:`نامهای مستعار عام <types-genericalias>`) یا نمونهای از آن باشد، ``True`` و در غیر این صورت ``False`` برمیگرداند."
msgid "If you need to know if a class is an instance of a dataclass (and not a dataclass itself), then add a further check for ``not isinstance(obj, type)``::"
msgstr "اگر نیاز دارید بدانید که آیا یک کلاس نمونهای از یک دیتاکلاس است (و نه خود یک دیتاکلاس)، آنگاه یک بررسی دیگر برای ``not isinstance(obj, type)`` اضافه کنید::"
msgid ""
"def is_dataclass_instance(obj):\n"
" return is_dataclass(obj) and not isinstance(obj, type)"
msgstr ""
"def is_dataclass_instance(obj):\n"
" return is_dataclass(obj) and not isinstance(obj, type)"
msgid "A sentinel value signifying a missing default or default_factory."
msgstr "یک مقدار نشانگر (sentinel) که نشاندهندهی نبود default یا default_factory است."
msgid "A sentinel value used as a type annotation. Any fields after a pseudo-field with the type of :const:`!KW_ONLY` are marked as keyword-only fields. Note that a pseudo-field of type :const:`!KW_ONLY` is otherwise completely ignored. This includes the name of such a field. By convention, a name of ``_`` is used for a :const:`!KW_ONLY` field. Keyword-only fields signify :meth:`~object.__init__` parameters that must be specified as keywords when the class is instantiated."
msgstr "یک مقدار نشانگر (sentinel value) که بهعنوان حاشیهنویسی نوع استفاده میشود. هر فیلدی که پس از یک شبهفیلد (pseudo-field) با نوع :const:`!KW_ONLY` قرار گیرد، بهعنوان فیلد فقط کلیدواژهای علامتگذاری میشود. توجه داشته باشید که یک شبهفیلد از نوع :const:`!KW_ONLY` در موارد دیگر بهطور کامل نادیده گرفته میشود. این موضوع شامل نام چنین فیلدی نیز میشود. طبق قرارداد، برای یک فیلد :const:`!KW_ONLY` از نام ``_`` استفاده میشود. فیلدهای فقط کلیدواژهای نشان میدهند که پارامترهای :meth:`~object.__init__` باید هنگام نمونهسازی از کلاس بهصورت کلیدواژه مشخص شوند."
msgid "In this example, the fields ``y`` and ``z`` will be marked as keyword-only fields::"
msgstr "در این مثال، فیلدهای ``y`` و ``z`` بهعنوان فیلدهای فقط کلیدواژهای علامتگذاری خواهند شد::"
msgid ""
"@dataclass\n"
"class Point:\n"
" x: float\n"
" _: KW_ONLY\n"
" y: float\n"
" z: float\n"
"\n"
"p = Point(0, y=1.5, z=2.0)"
msgstr ""
"@dataclass\n"
"class Point:\n"
" x: float\n"
" _: KW_ONLY\n"
" y: float\n"
" z: float\n"
"\n"
"p = Point(0, y=1.5, z=2.0)"
msgid "In a single dataclass, it is an error to specify more than one field whose type is :const:`!KW_ONLY`."
msgstr "در یک دیتاکلاس واحد، مشخص کردن بیش از یک فیلد که نوع آن :const:`!KW_ONLY` باشد، خطا است."
msgid "Raised when an implicitly defined :meth:`~object.__setattr__` or :meth:`~object.__delattr__` is called on a dataclass which was defined with ``frozen=True``. It is a subclass of :exc:`AttributeError`."
msgstr "هنگامی پرتاب میشود که یک :meth:`~object.__setattr__` یا :meth:`~object.__delattr__` تعریفشده بهصورت ضمنی، روی یک دیتاکلاس که با ``frozen=True`` تعریف شده باشد، فراخوانی شود. این استثنا زیرکلاسی از :exc:`AttributeError` است."
msgid "Post-init processing"
msgstr "پردازش پس از init"
msgid "When defined on the class, it will be called by the generated :meth:`~object.__init__`, normally as :meth:`!self.__post_init__`. However, if any ``InitVar`` fields are defined, they will also be passed to :meth:`!__post_init__` in the order they were defined in the class. If no :meth:`!__init__` method is generated, then :meth:`!__post_init__` will not automatically be called."
msgstr "هنگامی که در کلاس تعریف شود، توسط :meth:`~object.__init__` تولیدشده فراخوانی میشود، معمولاً بهصورت :meth:`!self.__post_init__`. با این حال، اگر فیلدهای ``InitVar`` تعریف شده باشند، آنها نیز به :meth:`!__post_init__` به همان ترتیبی که در کلاس تعریف شدهاند ارسال میشوند. اگر متد :meth:`!__init__` تولید نشود، در این صورت :meth:`!__post_init__` بهصورت خودکار فراخوانی نمیشود."
msgid "Among other uses, this allows for initializing field values that depend on one or more other fields. For example::"
msgstr "در میان سایر کاربردها، این امر امکان مقداردهی اولیهی مقادیر فیلدهایی را فراهم میکند که به یک یا چند فیلد دیگر وابستهاند. برای مثال::"
msgid ""
"@dataclass\n"
"class C:\n"
" a: float\n"
" b: float\n"
" c: float = field(init=False)\n"
"\n"
" def __post_init__(self):\n"
" self.c = self.a + self.b"
msgstr ""
"@dataclass\n"
"class C:\n"
" a: float\n"
" b: float\n"
" c: float = field(init=False)\n"
"\n"
" def __post_init__(self):\n"
" self.c = self.a + self.b"
msgid "The :meth:`~object.__init__` method generated by :deco:`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 "متد :meth:`~object.__init__` تولیدشده توسط :deco:`dataclass`، متدهای :meth:`!__init__` کلاس پایه را فراخوانی نمیکند. اگر کلاس پایه یک متد :meth:`!__init__` داشته باشد که باید فراخوانی شود، رایج است که این متد در یک متد :meth:`__post_init__` فراخوانی شود::"
msgid ""
"class Rectangle:\n"
" def __init__(self, height, width):\n"
" self.height = height\n"
" self.width = width\n"
"\n"
"@dataclass\n"
"class Square(Rectangle):\n"
" side: float\n"
"\n"
" def __post_init__(self):\n"
" super().__init__(self.side, self.side)"
msgstr ""
"class Rectangle:\n"
" def __init__(self, height, width):\n"
" self.height = height\n"
" self.width = width\n"
"\n"
"@dataclass\n"
"class Square(Rectangle):\n"
" side: float\n"
"\n"
" def __post_init__(self):\n"
" super().__init__(self.side, self.side)"
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 "با این حال، توجه داشته باشید که بهطور کلی نیازی به فراخوانی متدهای :meth:`!__init__` تولیدشده توسط دیتاکلاس نیست، زیرا دیتاکلاس مشتقشده مقداردهی اولیهی تمام فیلدهای هر کلاس پایهای که خود یک دیتاکلاس است را بر عهده میگیرد."
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 "برای روشهای ارسال پارامترها به :meth:`!__post_init__`، بخش زیر دربارهی متغیرهای فقط مقداردهی اولیه (init-only) را ببینید. همچنین هشدار دربارهی چگونگی مدیریت فیلدهای ``init=False`` توسط :func:`replace` را ببینید."
msgid "Class variables"
msgstr "متغیرهای کلاس"
msgid "One of the few places where :deco:`dataclass` actually inspects the type of a field is to determine if a field is a class variable as defined in :pep:`526`. It does this by checking if the type of the field is :data:`typing.ClassVar`. If a field is a ``ClassVar``, it is excluded from consideration as a field and is ignored by the dataclass mechanisms. Such ``ClassVar`` pseudo-fields are not returned by the module-level :func:`fields` function."
msgstr "یکی از معدود مواردی که :deco:`dataclass` در واقع نوع یک فیلد را بررسی میکند، تشخیص این است که آیا یک فیلد یک متغیر کلاس است، همانطور که در :pep:`526` تعریف شده است. این کار با بررسی اینکه آیا نوع فیلد :data:`typing.ClassVar` است انجام میشود. اگر یک فیلد ``ClassVar`` باشد، از در نظر گرفته شدن بهعنوان یک فیلد خارج میشود و سازوکارهای dataclass آن را نادیده میگیرند. چنین شبهفیلدهایی از جنس ``ClassVar`` توسط تابع :func:`fields` در سطح ماژول برگردانده نمیشوند."
msgid "Init-only variables"
msgstr "متغیرهای فقط مقداردهی اولیه"
msgid "Another place where :deco:`dataclass` inspects a type annotation is to determine if a field is an init-only variable. It does this by seeing if the type of a field is of type :class:`InitVar`. If a field is an :class:`InitVar`, it is considered a pseudo-field called an init-only field. As it is not a true field, it is not returned by the module-level :func:`fields` function. Init-only fields are added as parameters to the generated :meth:`~object.__init__` method, and are passed to the optional :meth:`__post_init__` method. They are not otherwise used by dataclasses."
msgstr "مورد دیگری که در آن :deco:`dataclass` یک حاشیهنویسی نوع را بررسی میکند، برای تشخیص این است که آیا یک فیلد یک متغیر فقط مقداردهی اولیه است یا خیر. این کار را با بررسی این انجام میدهد که آیا نوع یک فیلد از نوع :class:`InitVar` است یا خیر. اگر یک فیلد از نوع :class:`InitVar` باشد، بهعنوان یک شبهفیلد به نام فیلد فقط مقداردهی اولیه در نظر گرفته میشود. از آنجا که فیلد واقعی نیست، توسط تابع :func:`fields` در سطح ماژول برگردانده نمیشود. فیلدهای فقط مقداردهی اولیه بهعنوان پارامتر به متد تولیدشدهی :meth:`~object.__init__` اضافه میشوند، و به متد اختیاری :meth:`__post_init__` ارسال میشوند. بهجز این موارد، دیتاکلاسها از آنها استفاده نمیکنند."
msgid "For example, suppose a field will be initialized from a database, if a value is not provided when creating the class::"
msgstr "برای مثال، فرض کنید اگر هنگام ایجاد کلاس مقداری ارائه نشود، یک فیلد از پایگاه داده مقداردهی اولیه میشود::"
msgid ""
"@dataclass\n"
"class C:\n"
" i: int\n"
" j: int | None = None\n"
" database: InitVar[DatabaseType | None] = None\n"
"\n"
" def __post_init__(self, database):\n"
" if self.j is None and database is not None:\n"
" self.j = database.lookup('j')\n"
"\n"
"c = C(10, database=my_database)"
msgstr ""
"@dataclass\n"
"class C:\n"
" i: int\n"
" j: int | None = None\n"
" database: InitVar[DatabaseType | None] = None\n"
"\n"
" def __post_init__(self, database):\n"
" if self.j is None and database is not None:\n"
" self.j = database.lookup('j')\n"
"\n"
"c = C(10, database=my_database)"
msgid "In this case, :func:`fields` will return :class:`Field` objects for :attr:`!i` and :attr:`!j`, but not for :attr:`!database`."
msgstr "در این حالت، :func:`fields` اشیاء :class:`Field` را برای :attr:`!i` و :attr:`!j` برمیگرداند، اما نه برای :attr:`!database`."
msgid "Frozen instances"
msgstr "نمونههای فریزشده"
msgid "It is not possible to create truly immutable Python objects. However, by passing ``frozen=True`` to the :deco:`dataclass` decorator you can emulate immutability. In that case, dataclasses will add :meth:`~object.__setattr__` and :meth:`~object.__delattr__` methods to the class. These methods will raise a :exc:`FrozenInstanceError` when invoked."
msgstr "ایجاد اشیای پایتونی که واقعاً تغییرناپذیر باشند، امکانپذیر نیست. با این حال، با ارسال ``frozen=True`` به دکوراتور :deco:`dataclass` میتوانید تغییرناپذیری را شبیهسازی کنید. در این صورت، دیتاکلاسها متدهای :meth:`~object.__setattr__` و :meth:`~object.__delattr__` را به کلاس اضافه میکنند. این متدها هنگام فراخوانی، :exc:`FrozenInstanceError` را پرتاب میکنند."
msgid "There is a tiny performance penalty when using ``frozen=True``: :meth:`~object.__init__` cannot use simple assignment to initialize fields, and must use :meth:`!object.__setattr__`."
msgstr "هنگام استفاده از ``frozen=True``، هزینه عملکردی بسیار کمی وجود دارد: :meth:`~object.__init__` نمیتواند از انتساب ساده برای مقداردهی اولیه فیلدها استفاده کند و باید از :meth:`!object.__setattr__` استفاده کند."
msgid "Inheritance"
msgstr "وراثت"
msgid "When the dataclass is being created by the :deco:`dataclass` decorator, it looks through all of the class's base classes in reverse MRO (that is, starting at :class:`object`) and, for each dataclass that it finds, adds the fields from that base class to an ordered mapping of fields. After all of the base class fields are added, it adds its own fields to the ordered mapping. All of the generated methods will use this combined, calculated ordered mapping of fields. Because the fields are in insertion order, derived classes override base classes. An example::"
msgstr "هنگامی که دیتاکلاس توسط دکوراتور :deco:`dataclass` ایجاد میشود، این دکوراتور همهی کلاسهای پایهی کلاس را در MRO معکوس (یعنی با شروع از :class:`object`) بررسی میکند و برای هر دیتاکلاسی که پیدا کند، فیلدهای آن کلاس پایه را به یک نگاشت مرتب از فیلدها اضافه میکند. پس از افزودن همهی فیلدهای کلاسهای پایه، فیلدهای خودش را به نگاشت مرتب اضافه میکند. همهی متدهای تولیدشده از این نگاشت مرتبِ محاسبهشده و ترکیبی فیلدها استفاده خواهند کرد. چون فیلدها به ترتیب درج قرار دارند، کلاسهای مشتقشده کلاسهای پایه را میپوشانند. یک مثال::"
msgid ""
"@dataclass\n"
"class Base:\n"
" x: Any = 15.0\n"
" y: int = 0\n"
"\n"
"@dataclass\n"
"class C(Base):\n"
" z: int = 10\n"
" x: int = 15"
msgstr ""
"@dataclass\n"
"class Base:\n"
" x: Any = 15.0\n"
" y: int = 0\n"
"\n"
"@dataclass\n"
"class C(Base):\n"
" z: int = 10\n"
" x: int = 15"
msgid "The final list of fields is, in order, :attr:`!x`, :attr:`!y`, :attr:`!z`. The final type of :attr:`!x` is :class:`int`, as specified in class :class:`!C`."
msgstr "فهرست نهایی فیلدها، به ترتیب، :attr:`!x`، :attr:`!y`، :attr:`!z` است. نوع نهایی :attr:`!x`، :class:`int` است، همانطور که در کلاس :class:`!C` مشخص شده است."
msgid "The generated :meth:`~object.__init__` method for :class:`!C` will look like::"
msgstr "متد :meth:`~object.__init__` تولیدشده برای :class:`!C` بهشکل زیر خواهد بود::"
msgid "def __init__(self, x: int = 15, y: int = 0, z: int = 10):"
msgstr "def __init__(self, x: int = 15, y: int = 0, z: int = 10):"
msgid "Re-ordering of keyword-only parameters in :meth:`!__init__`"
msgstr "تغییر ترتیب پارامترهای فقط کلیدواژهای در :meth:`!__init__`"
msgid "After the parameters needed for :meth:`~object.__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 "پس از این که پارامترهای مورد نیاز برای :meth:`~object.__init__` محاسبه شدند، همهی پارامترهای فقط کلیدواژهای جابهجا میشوند تا پس از تمام پارامترهای معمولی (غیر فقط کلیدواژهای) قرار بگیرند. این یک الزام در نحوهی پیادهسازی پارامترهای فقط کلیدواژهای در پایتون است: آنها باید پس از پارامترهای غیر فقط کلیدواژهای بیایند."
msgid "In this example, :attr:`!Base.y`, :attr:`!Base.w`, and :attr:`!D.t` are keyword-only fields, and :attr:`!Base.x` and :attr:`!D.z` are regular fields::"
msgstr "در این مثال، :attr:`!Base.y`، :attr:`!Base.w` و :attr:`!D.t` فیلدهای فقط کلیدواژهای هستند و :attr:`!Base.x` و :attr:`!D.z` فیلدهای معمولی هستند::"
msgid ""
"@dataclass\n"
"class Base:\n"
" x: Any = 15.0\n"
" _: KW_ONLY\n"
" y: int = 0\n"
" w: int = 1\n"
"\n"
"@dataclass\n"
"class D(Base):\n"
" z: int = 10\n"
" t: int = field(kw_only=True, default=0)"
msgstr ""
"@dataclass\n"
"class Base:\n"
" x: Any = 15.0\n"
" _: KW_ONLY\n"
" y: int = 0\n"
" w: int = 1\n"
"\n"
"@dataclass\n"
"class D(Base):\n"
" z: int = 10\n"
" t: int = field(kw_only=True, default=0)"
msgid "The generated :meth:`!__init__` method for :class:`!D` will look like::"
msgstr "متد تولیدشدهی :meth:`!__init__` برای :class:`!D` بهصورت زیر خواهد بود::"
msgid "def __init__(self, x: Any = 15.0, z: int = 10, *, y: int = 0, w: int = 1, t: int = 0):"
msgstr "def __init__(self, x: Any = 15.0, z: int = 10, *, y: int = 0, w: int = 1, t: int = 0):"
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 "توجه داشته باشید که پارامترها نسبت به آنچه در فهرست فیلدها آمده است دوباره مرتب شدهاند: پس از پارامترهای حاصل از فیلدهای عادی، پارامترهای حاصل از فیلدهای فقط کلیدواژهای میآیند."
msgid "The relative ordering of keyword-only parameters is maintained in the re-ordered :meth:`!__init__` parameter list."
msgstr "ترتیب نسبی پارامترهای فقط کلیدواژهای در فهرست پارامترهای :meth:`!__init__` که دوباره مرتبشده است، حفظ میشود."
msgid "Default factory functions"
msgstr "توابع کارخانه پیشفرض"
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 "اگر یک :func:`field` یک *default_factory* تعیین کند، هنگامی که به یک مقدار پیشفرض برای آن فیلد نیاز باشد، با صفر آرگومان فراخوانی میشود. برای مثال، برای ایجاد یک نمونه جدید از فهرست، بهصورت زیر عمل کنید::"
msgid "mylist: list = field(default_factory=list)"
msgstr "mylist: list = field(default_factory=list)"
msgid "If a field is excluded from :meth:`~object.__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 "اگر یک فیلد از :meth:`~object.__init__` حذفشده باشد (با استفاده از ``init=False``) و برای آن فیلد همچنین *default_factory* مشخصشده باشد، آنگاه تابع کارخانهی پیشفرض همیشه از تابع :meth:`!__init__` تولیدشده فراخوانی میشود. این امر به این دلیل است که هیچ راه دیگری برای دادن یک مقدار اولیه به فیلد وجود ندارد."
msgid "Mutable default values"
msgstr "مقادیر پیشفرض تغییرپذیر"
msgid "Python stores default member variable values in class attributes. Consider this example, not using dataclasses::"
msgstr "پایتون مقادیر پیشفرض متغیرهای عضو را در ویژگیهای کلاس ذخیره میکند. این مثال را در نظر بگیرید که از dataclasses استفاده نمیکند::"
msgid ""
"class C:\n"
" x = []\n"
" def add(self, element):\n"
" self.x.append(element)\n"
"\n"
"o1 = C()\n"
"o2 = C()\n"
"o1.add(1)\n"
"o2.add(2)\n"
"assert o1.x == [1, 2]\n"
"assert o1.x is o2.x"
msgstr ""
"class C:\n"
" x = []\n"
" def add(self, element):\n"
" self.x.append(element)\n"
"\n"
"o1 = C()\n"
"o2 = C()\n"
"o1.add(1)\n"
"o2.add(2)\n"
"assert o1.x == [1, 2]\n"
"assert o1.x is o2.x"
msgid "Note that the two instances of class :class:`!C` share the same class variable :attr:`!x`, as expected."
msgstr "توجه داشته باشید که دو نمونه از کلاس :class:`!C`، همانطور که انتظار میرود، همان متغیر کلاس :attr:`!x` را به اشتراک میگذارند."
msgid "Using dataclasses, *if* this code was valid::"
msgstr "با استفاده از dataclasses، *اگر* این کد معتبر بود::"
msgid ""
"@dataclass\n"
"class D:\n"
" x: list = [] # This code raises ValueError\n"
" def add(self, element):\n"
" self.x.append(element)"
msgstr ""
"@dataclass\n"
"class D:\n"
" x: list = [] # This code raises ValueError\n"
" def add(self, element):\n"
" self.x.append(element)"
msgid "it would generate code similar to::"
msgstr "کدی مشابه زیر تولید میشود::"
msgid ""
"class D:\n"
" x = []\n"
" def __init__(self, x=x):\n"
" self.x = x\n"
" def add(self, element):\n"
" self.x.append(element)\n"
"\n"
"assert D().x is D().x"
msgstr ""
"class D:\n"
" x = []\n"
" def __init__(self, x=x):\n"
" self.x = x\n"
" def add(self, element):\n"
" self.x.append(element)\n"
"\n"
"assert D().x is D().x"
msgid "This has the same issue as the original example using class :class:`!C`. That is, two instances of class :class:`!D` that do not specify a value for :attr:`!x` when creating a class instance will share the same copy of :attr:`!x`. Because dataclasses just use normal Python class creation they also share this behavior. There is no general way for Data Classes to detect this condition. Instead, the :deco:`dataclass` decorator will raise a :exc:`ValueError` if it detects an unhashable default parameter. The assumption is that if a value is unhashable, it is mutable. This is a partial solution, but it does protect against many common errors."
msgstr "این همان مشکلی است که مثال اصلی با استفاده از کلاس :class:`!C` داشت. یعنی دو نمونه از کلاس :class:`!D` که هنگام ایجاد یک نمونه کلاس، مقداری برای :attr:`!x` تعیین نمیکنند، نسخه یکسانی از :attr:`!x` را به اشتراک میگذارند. از آنجا که کلاسهای داده صرفاً از ایجاد کلاس معمولی پایتون استفاده میکنند، آنها نیز همین رفتار را دارند. کلاسهای داده هیچ راه کلی برای تشخیص این وضعیت ندارند. در عوض، دکوراتور :deco:`dataclass` در صورت تشخیص یک پارامتر پیشفرض هشناپذیر (unhashable)، یک :exc:`ValueError` پرتاب میکند. فرض بر این است که اگر یک مقدار هشناپذیر (unhashable) باشد، تغییرپذیر است. این یک راهحل نسبی است، اما در برابر بسیاری از خطاهای رایج محافظت میکند."
msgid "Using default factory functions is a way to create new instances of mutable types as default values for fields::"
msgstr "استفاده از توابع کارخانه پیشفرض راهی برای ایجاد نمونههای جدید از انواع تغییرپذیر بهعنوان مقادیر پیشفرض برای فیلدها است::"
msgid ""
"@dataclass\n"
"class D:\n"
" x: list = field(default_factory=list)\n"
"\n"
"assert D().x is not D().x"
msgstr ""
"@dataclass\n"
"class D:\n"
" x: list = field(default_factory=list)\n"
"\n"
"assert D().x is not D().x"
msgid "Instead of looking for and disallowing objects of type :class:`list`, :class:`dict`, or :class:`set`, unhashable objects are now not allowed as default values. Unhashability is used to approximate mutability."
msgstr "بهجای جستوجو و ممنوعکردن اشیایی از نوع :class:`list`، :class:`dict` یا :class:`set`، اکنون اشیای هشناپذیر بهعنوان مقادیر پیشفرض مجاز نیستند. از هشناپذیری برای تقریبزدن تغییرپذیری استفاده میشود."
msgid "Descriptor-typed fields"
msgstr "فیلدهای نوع توصیفگر"
msgid "Fields that are assigned :ref:`descriptor objects <descriptors>` as their default value have the following special behaviors:"
msgstr "فیلدهایی که :ref:`اشیای توصیفگر (descriptor objects) <descriptors>` بهعنوان مقدار پیشفرض آنها تخصیص داده شدهاند، رفتارهای ویژه زیر را دارند:"
msgid "The value for the field passed to the dataclass's :meth:`~object.__init__` method is passed to the descriptor's :meth:`~object.__set__` method rather than overwriting the descriptor object."
msgstr "مقداری که برای فیلد به متد :meth:`~object.__init__` دیتاکلاس ارسال میشود، به متد :meth:`~object.__set__` توصیفگر ارسال میشود، نه اینکه شیء توصیفگر بازنویسی شود."
msgid "Similarly, when getting or setting the field, the descriptor's :meth:`~object.__get__` or :meth:`!__set__` method is called rather than returning or overwriting the descriptor object."
msgstr "به همین ترتیب، هنگام دریافت یا تنظیم فیلد، به جای بازگرداندن یا بازنویسی شیء توصیفگر، متد :meth:`~object.__get__` یا :meth:`!__set__` توصیفگر فراخوانی میشود."
msgid "To determine whether a field contains a default value, :deco:`dataclass` will call the descriptor's :meth:`!__get__` method using its class access form: ``descriptor.__get__(obj=None, type=cls)``. If the descriptor returns a value in this case, it will be used as the field's default. On the other hand, if the descriptor raises :exc:`AttributeError` in this situation, no default value will be provided for the field."
msgstr "برای تشخیص اینکه آیا یک فیلد دارای مقدار پیشفرض است، :deco:`dataclass` متد :meth:`!__get__` توصیفگر را با استفاده از شکل دسترسی کلاسی آن فراخوانی میکند: ``descriptor.__get__(obj=None, type=cls)``. اگر توصیفگر در این حالت مقداری برگرداند، آن مقدار بهعنوان مقدار پیشفرض فیلد استفاده خواهد شد. از سوی دیگر، اگر توصیفگر در این موقعیت :exc:`AttributeError` را پرتاب کند، هیچ مقدار پیشفرضی برای فیلد ارائه نخواهد شد."
msgid ""
"class IntConversionDescriptor:\n"
" def __init__(self, *, default):\n"
" self._default = default\n"
"\n"
" def __set_name__(self, owner, name):\n"
" self._name = \"_\" + name\n"
"\n"
" def __get__(self, obj, type):\n"
" if obj is None:\n"
" return self._default\n"
"\n"
" return getattr(obj, self._name, self._default)\n"
"\n"
" def __set__(self, obj, value):\n"
" setattr(obj, self._name, int(value))\n"
"\n"
"@dataclass\n"
"class InventoryItem:\n"
" quantity_on_hand: IntConversionDescriptor = IntConversionDescriptor(default=100)\n"
"\n"
"i = InventoryItem()\n"
"print(i.quantity_on_hand) # 100\n"
"i.quantity_on_hand = 2.5 # calls __set__ with 2.5\n"
"print(i.quantity_on_hand) # 2"
msgstr ""
"class IntConversionDescriptor:\n"
" def __init__(self, *, default):\n"
" self._default = default\n"
"\n"
" def __set_name__(self, owner, name):\n"
" self._name = \"_\" + name\n"
"\n"
" def __get__(self, obj, type):\n"
" if obj is None:\n"
" return self._default\n"
"\n"
" return getattr(obj, self._name, self._default)\n"
"\n"
" def __set__(self, obj, value):\n"
" setattr(obj, self._name, int(value))\n"
"\n"
"@dataclass\n"
"class InventoryItem:\n"
" quantity_on_hand: IntConversionDescriptor = IntConversionDescriptor(default=100)\n"
"\n"
"i = InventoryItem()\n"
"print(i.quantity_on_hand) # 100\n"
"i.quantity_on_hand = 2.5 # calls __set__ with 2.5\n"
"print(i.quantity_on_hand) # 2"
msgid "Note that if a field is annotated with a descriptor type, but is not assigned a descriptor object as its default value, the field will act like a normal field."
msgstr "توجه داشته باشید که اگر یک فیلد با یک نوع توصیفگر حاشیهنویسی شده باشد، اما یک شیء توصیفگر بهعنوان مقدار پیشفرض آن تخصیص داده نشده باشد، آن فیلد مانند یک فیلد معمولی رفتار خواهد کرد."