Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 8ac1732

Browse files
committedFeb 17, 2025··
wip
1 parent 06b05d9 commit 8ac1732

File tree

1 file changed

+292
-54
lines changed

1 file changed

+292
-54
lines changed
 

‎howto/mro.po

+292-54
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
# Copyright (C) 2001-2024, Python Software Foundation
1+
# Copyright (C) 2001-2025, Python Software Foundation
22
# This file is distributed under the same license as the Python package.
3-
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
3+
# Translators:
4+
# Matt Wang <mattwang44@gmail.com>, 2025
45
#
56
#, fuzzy
67
msgid ""
@@ -9,7 +10,7 @@ msgstr ""
910
"Report-Msgid-Bugs-To: \n"
1011
"POT-Creation-Date: 2025-01-22 00:13+0000\n"
1112
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
12-
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13+
"Last-Translator: Matt Wang <mattwang44@gmail.com>\n"
1314
"Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-"
1415
"tw)\n"
1516
"Language: zh_TW\n"
@@ -19,49 +20,61 @@ msgstr ""
1920

2021
#: ../../howto/mro.rst:4
2122
msgid "The Python 2.3 Method Resolution Order"
22-
msgstr ""
23+
msgstr "Python 2.3 方法解析順序"
2324

2425
#: ../../howto/mro.rst:8
26+
#, fuzzy
2527
msgid ""
2628
"This is a historical document, provided as an appendix to the official "
2729
"documentation. The Method Resolution Order discussed here was *introduced* "
2830
"in Python 2.3, but it is still used in later versions -- including Python 3."
2931
msgstr ""
32+
"這是一份歷史文件,作為官方文件的附錄。這裡討論的方法解析順序是在 Python 2.3 "
33+
"中「引入」的,但它仍在更高版本中使用——包括 Python 3。"
3034

3135
#: ../../howto/mro.rst:13
3236
msgid "By `Michele Simionato <https://www.phyast.pitt.edu/~micheles/>`__."
33-
msgstr ""
37+
msgstr "作者:`Michele Simionato <https://www.phyast.pitt.edu/~micheles/>`__。"
3438

3539
#: ../../howto/mro.rst:0
3640
msgid "Abstract"
3741
msgstr "摘要"
3842

3943
#: ../../howto/mro.rst:17
44+
#, fuzzy
4045
msgid ""
4146
"*This document is intended for Python programmers who want to understand the "
4247
"C3 Method Resolution Order used in Python 2.3. Although it is not intended "
4348
"for newbies, it is quite pedagogical with many worked out examples. I am "
4449
"not aware of other publicly available documents with the same scope, "
4550
"therefore it should be useful.*"
4651
msgstr ""
52+
"*本文件適用於想要了解 Python 2.3 中所使用的 C3 方法解析順序的 Python 程式設計"
53+
"師。儘管它不適合新手,但它具有許多教學意義,並提供了許多範例。我不知道其他具"
54+
"有相同範圍的公開文件,因此它應該有用。"
4755

4856
#: ../../howto/mro.rst:23
4957
msgid "Disclaimer:"
50-
msgstr ""
58+
msgstr "免責聲明:"
5159

5260
#: ../../howto/mro.rst:25
61+
#, fuzzy
5362
msgid ""
5463
"*I donate this document to the Python Software Foundation, under the Python "
5564
"2.3 license. As usual in these circumstances, I warn the reader that what "
5665
"follows* should *be correct, but I don't give any warranty. Use it at your "
5766
"own risk and peril!*"
5867
msgstr ""
68+
"*我根據 Python 2.3 許可證將本文件捐贈給 Python 軟體基金會。像往常一樣,在這些"
69+
"情況下,我警告讀者以下內容*應該是正確的,但我不提供任何保證。使用它需要你自擔"
70+
"風險和危險!"
5971

6072
#: ../../howto/mro.rst:30
6173
msgid "Acknowledgments:"
62-
msgstr "致謝"
74+
msgstr "致謝"
6375

6476
#: ../../howto/mro.rst:32
77+
#, fuzzy
6578
msgid ""
6679
"*All the people of the Python mailing list who sent me their support. Paul "
6780
"Foley who pointed out various imprecisions and made me to add the part on "
@@ -70,16 +83,22 @@ msgid ""
7083
"Rossum who enthusiastically added this document to the official Python 2.3 "
7184
"home-page.*"
7285
msgstr ""
86+
"*Python 郵件清單中所有向我發送支援的人。Paul Foley 指出了各種不精確之處,並讓"
87+
"我加入有關區域優先順序的部分。David Goodger 尋求有關 reStructuredText 格式設"
88+
"定的協助。David Mertz 尋求編輯協助。最後,Guido van Rossum 熱情地將此文件新增"
89+
"到官方 Python 2.3 主頁。"
7390

7491
#: ../../howto/mro.rst:40
92+
#, fuzzy
7593
msgid "The beginning"
76-
msgstr ""
94+
msgstr "開始"
7795

7896
#: ../../howto/mro.rst:42
7997
msgid "*Felix qui potuit rerum cognoscere causas* -- Virgilius"
80-
msgstr ""
98+
msgstr "*Felix qui potuit rerum cognoscere causas* -- Virgilius"
8199

82100
#: ../../howto/mro.rst:44
101+
#, fuzzy
83102
msgid ""
84103
"Everything started with a post by Samuele Pedroni to the Python development "
85104
"mailing list [#]_. In his post, Samuele showed that the Python 2.2 method "
@@ -91,8 +110,15 @@ msgid ""
91110
"readable discussion of the C3 algorithm for Pythonistas who want to "
92111
"understand the reasons for the change."
93112
msgstr ""
113+
"一切都始於 Samuele Pedroni 在 Python 開發郵件清單 [#]_ 上發表的一篇文章。"
114+
"Samuele 在他的文章中表明,Python 2.2 方法解析順序不是單調的,他建議用 C3 方法"
115+
"解析順序取代它。Guido 同意他的觀點,因此現在 Python 2.3 使用 C3。C3 方法本身"
116+
"與 Python 無關,因為它是由 Dylan 的工作人員發明的,並且在一篇針對 lispers "
117+
"[#]_ 的論文中對其進行了描述。本文對 C3 演演算法進行了(希望)可讀的討論,供那"
118+
"些想要了解更改原因的 Python 愛好者參考。"
94119

95120
#: ../../howto/mro.rst:55
121+
#, fuzzy
96122
msgid ""
97123
"First of all, let me point out that what I am going to say only applies to "
98124
"the *new style classes* introduced in Python 2.2: *classic classes* "
@@ -103,46 +129,64 @@ msgid ""
103129
"differs from the Python 2.2 method resolution order are so rare that no real "
104130
"breaking of code is expected. Therefore:"
105131
msgstr ""
132+
"首先,讓我指出,我要說的內容僅適用於 Python 2.2 中引入的「新樣式類別」:「經"
133+
"典類別」保持其舊的方法解析順序,深度優先,然後從左到右。因此,經典類別不會破"
134+
"壞舊程式碼;即使原則上可能會破壞 Python 2.2 新樣式類別的程式碼,但實際上,C3 "
135+
"解析順序與 Python 2.2 方法解析順序不同的情況非常罕見,因此不會出現真正的程式"
136+
"碼破壞。所以:"
106137

107138
#: ../../howto/mro.rst:64
108139
msgid "*Don't be scared!*"
109-
msgstr ""
140+
msgstr "*別怕!*"
110141

111142
#: ../../howto/mro.rst:66
143+
#, fuzzy
112144
msgid ""
113145
"Moreover, unless you make strong use of multiple inheritance and you have "
114146
"non-trivial hierarchies, you don't need to understand the C3 algorithm, and "
115147
"you can easily skip this paper. On the other hand, if you really want to "
116148
"know how multiple inheritance works, then this paper is for you. The good "
117149
"news is that things are not as complicated as you might expect."
118150
msgstr ""
151+
"此外,除非你強烈使用多重繼承並且你具有重要的層次結構,否則你不需要了解 C3 演"
152+
"演算法,並且可以輕鬆跳過本文。另一方面,如果你確實想了解多重繼承是如何運作"
153+
"的,那麼本文適合你。好消息是事情並不像你想像的那麼複雜。"
119154

120155
#: ../../howto/mro.rst:73
121156
msgid "Let me begin with some basic definitions."
122-
msgstr ""
157+
msgstr "讓我從一些基本定義開始。"
123158

124159
#: ../../howto/mro.rst:75
160+
#, fuzzy
125161
msgid ""
126162
"Given a class C in a complicated multiple inheritance hierarchy, it is a non-"
127163
"trivial task to specify the order in which methods are overridden, i.e. to "
128164
"specify the order of the ancestors of C."
129165
msgstr ""
166+
"給定一個複雜的多重繼承層次結構中的類別 C,指定方法被重寫的順序(即指定 C 的祖"
167+
"先的順序)是一項艱鉅的任務。"
130168

131169
#: ../../howto/mro.rst:79
170+
#, fuzzy
132171
msgid ""
133172
"The list of the ancestors of a class C, including the class itself, ordered "
134173
"from the nearest ancestor to the furthest, is called the class precedence "
135174
"list or the *linearization* of C."
136175
msgstr ""
176+
"類別 C 的祖先清單(包括類別本身)從最近的祖先到最遠的祖先排序,稱為類別優先列"
177+
"表或 C 的\\ *線性化 (linearization)*。"
137178

138179
#: ../../howto/mro.rst:83
139180
msgid ""
140181
"The *Method Resolution Order* (MRO) is the set of rules that construct the "
141182
"linearization. In the Python literature, the idiom \"the MRO of C\" is also "
142183
"used as a synonymous for the linearization of the class C."
143184
msgstr ""
185+
"*方法解析順序* (Method Resolution Order, MRO) 是建構線性化的一組規則。在 "
186+
"Python 文獻中,習慣用語「C 的 MRO」也是 C 類別線性化的同義詞。"
144187

145188
#: ../../howto/mro.rst:88
189+
#, fuzzy
146190
msgid ""
147191
"For instance, in the case of single inheritance hierarchy, if C is a "
148192
"subclass of C1, and C1 is a subclass of C2, then the linearization of C is "
@@ -151,8 +195,13 @@ msgid ""
151195
"it is more difficult to construct a linearization that respects *local "
152196
"precedence ordering* and *monotonicity*."
153197
msgstr ""
198+
"例如,在單一繼承層次結構的情況下,如果 C 是 C1 的子類別,且 C1 是 C2 的子類"
199+
"別,那麼 C 的線性化就是串列 [C, C1 , C2]。然而,對於多重繼承層次結構,線性化"
200+
"的建構更加麻煩,因為建構尊重\\ *局部優先順序 (local precedence ordering)*\\ "
201+
"和\\ *單調性 (monotonicity)*\\ 的線性化更加困難。"
154202

155203
#: ../../howto/mro.rst:96
204+
#, fuzzy
156205
msgid ""
157206
"I will discuss the local precedence ordering later, but I can give the "
158207
"definition of monotonicity here. A MRO is monotonic when the following is "
@@ -162,24 +211,35 @@ msgid ""
162211
"potentially introducing very subtle bugs. Examples where this happens will "
163212
"be shown later."
164213
msgstr ""
214+
"稍後我將討論局部優先順序,但我可以在這裡給出單調性的定義。當滿足以下條件時,"
215+
"MRO 是單調的:*如果在 C 的線性化中 C1 領先於 C2,則在 C 的任何子類別的線性化"
216+
"中 C1 領先於 C2*。否則,衍生新類別的無害操作可能會改變方法的解析順序,從而可"
217+
"能引入非常微妙的錯誤。稍後將顯示發生這種情況的範例。"
165218

166219
#: ../../howto/mro.rst:104
220+
#, fuzzy
167221
msgid ""
168222
"Not all classes admit a linearization. There are cases, in complicated "
169223
"hierarchies, where it is not possible to derive a class such that its "
170224
"linearization respects all the desired properties."
171225
msgstr ""
226+
"並非所有類別都承認線性化。在某些情況下,在複雜的層次結構中,不可能衍生出一個"
227+
"類別,使其線性化尊重所有所需的屬性。"
172228

173229
#: ../../howto/mro.rst:108
230+
#, fuzzy
174231
msgid "Here I give an example of this situation. Consider the hierarchy"
175-
msgstr ""
232+
msgstr "這裡我舉一個例子來說明這種情況。考慮層次結構"
176233

177234
#: ../../howto/mro.rst:116
235+
#, fuzzy
178236
msgid ""
179237
"which can be represented with the following inheritance graph, where I have "
180238
"denoted with O the ``object`` class, which is the beginning of any hierarchy "
181239
"for new style classes:"
182240
msgstr ""
241+
"可以用下面的繼承圖來表示,其中我用 O 表示 ``object`` 類別,它是新樣式類別的任"
242+
"何層次結構的開始:"
183243

184244
#: ../../howto/mro.rst:120
185245
msgid ""
@@ -206,108 +266,131 @@ msgstr ""
206266
" ?"
207267

208268
#: ../../howto/mro.rst:133
269+
#, fuzzy
209270
msgid ""
210271
"In this case, it is not possible to derive a new class C from A and B, since "
211272
"X precedes Y in A, but Y precedes X in B, therefore the method resolution "
212273
"order would be ambiguous in C."
213274
msgstr ""
275+
"在這種情況下,不可能從 A 和 B 衍生出新的類別 C,因為在 A 中 X 在 Y 之前,但"
276+
"在 B 中 Y 在 X 之前,因此 C 中的方法解析順序將不明確。"
214277

215278
#: ../../howto/mro.rst:137
279+
#, fuzzy
216280
msgid ""
217281
"Python 2.3 raises an exception in this situation (TypeError: MRO conflict "
218282
"among bases Y, X) forbidding the naive programmer from creating ambiguous "
219283
"hierarchies. Python 2.2 instead does not raise an exception, but chooses an "
220284
"*ad hoc* ordering (CABXYO in this case)."
221285
msgstr ""
286+
"Python 2.3 在這種情況下引發了一個例外(TypeError:基數 Y、X 之間的 MRO 衝"
287+
"突),禁止天真的程式設計師建立不明確的層次結構。 相反,Python 2.2 不會引發例"
288+
"外,而是選擇*暫時* 排序(在本例中為 CABXYO)。"
222289

223290
#: ../../howto/mro.rst:143
291+
#, fuzzy
224292
msgid "The C3 Method Resolution Order"
225-
msgstr ""
293+
msgstr "C3 方法解析順序"
226294

227295
#: ../../howto/mro.rst:145
296+
#, fuzzy
228297
msgid ""
229298
"Let me introduce a few simple notations which will be useful for the "
230299
"following discussion. I will use the shortcut notation::"
231-
msgstr ""
300+
msgstr "讓我介紹一些對下面的討論有用的簡單符號。 我將使用快捷符號::"
232301

233302
#: ../../howto/mro.rst:148
234303
msgid "C1 C2 ... CN"
235304
msgstr "C1 C2 ... CN"
236305

237306
#: ../../howto/mro.rst:150
307+
#, fuzzy
238308
msgid "to indicate the list of classes [C1, C2, ... , CN]."
239-
msgstr ""
309+
msgstr "指示類別串列 [C1, C2, ... , CN]。"
240310

241311
#: ../../howto/mro.rst:152
312+
#, fuzzy
242313
msgid "The *head* of the list is its first element::"
243-
msgstr ""
314+
msgstr "串列的 *head* 是它的第一個元素: ::"
244315

245316
#: ../../howto/mro.rst:154
246317
msgid "head = C1"
247318
msgstr "head = C1"
248319

249320
#: ../../howto/mro.rst:156
321+
#, fuzzy
250322
msgid "whereas the *tail* is the rest of the list::"
251-
msgstr ""
323+
msgstr "而 *tail* 是清單的其餘部分: ::"
252324

253325
#: ../../howto/mro.rst:158
254326
msgid "tail = C2 ... CN."
255327
msgstr "tail = C2 ... CN."
256328

257329
#: ../../howto/mro.rst:160
330+
#, fuzzy
258331
msgid "I shall also use the notation::"
259-
msgstr ""
332+
msgstr "我也會使用符號: ::"
260333

261334
#: ../../howto/mro.rst:162
262335
msgid "C + (C1 C2 ... CN) = C C1 C2 ... CN"
263336
msgstr "C + (C1 C2 ... CN) = C C1 C2 ... CN"
264337

265338
#: ../../howto/mro.rst:164
339+
#, fuzzy
266340
msgid "to denote the sum of the lists [C] + [C1, C2, ... ,CN]."
267-
msgstr ""
341+
msgstr "表示串列 [C] + [C1, C2, ... ,CN] 的總和。"
268342

269343
#: ../../howto/mro.rst:166
344+
#, fuzzy
270345
msgid "Now I can explain how the MRO works in Python 2.3."
271-
msgstr ""
346+
msgstr "現在我可以解釋 MRO 在 Python 2.3 中是如何運作的。"
272347

273348
#: ../../howto/mro.rst:168
349+
#, fuzzy
274350
msgid ""
275351
"Consider a class C in a multiple inheritance hierarchy, with C inheriting "
276352
"from the base classes B1, B2, ... , BN. We want to compute the "
277353
"linearization L[C] of the class C. The rule is the following:"
278354
msgstr ""
355+
"考慮多重繼承層次結構中的類別 C,其中 C 繼承自基底類別 B1, B2, ... , BN。我們"
356+
"要計算 C 類別的線性化 L[C]。"
279357

280358
#: ../../howto/mro.rst:173
359+
#, fuzzy
281360
msgid ""
282361
"*the linearization of C is the sum of C plus the merge of the linearizations "
283362
"of the parents and the list of the parents.*"
284-
msgstr ""
363+
msgstr "*C 的線性化是 C 的總和加上父級線性化和父級串列的合併。"
285364

286365
#: ../../howto/mro.rst:176
287366
msgid "In symbolic notation::"
288-
msgstr ""
367+
msgstr "用符號標示法: ::"
289368

290369
#: ../../howto/mro.rst:178
291370
msgid "L[C(B1 ... BN)] = C + merge(L[B1] ... L[BN], B1 ... BN)"
292371
msgstr "L[C(B1 ... BN)] = C + merge(L[B1] ... L[BN], B1 ... BN)"
293372

294373
#: ../../howto/mro.rst:180
374+
#, fuzzy
295375
msgid ""
296376
"In particular, if C is the ``object`` class, which has no parents, the "
297377
"linearization is trivial::"
298378
msgstr ""
379+
"特別是,如果 C 是沒有父類別的 ``object`` 類別,則線性化是微不足道的: ::"
299380

300381
#: ../../howto/mro.rst:183
301382
msgid "L[object] = object."
302383
msgstr "L[object] = object."
303384

304385
#: ../../howto/mro.rst:185
386+
#, fuzzy
305387
msgid ""
306388
"However, in general one has to compute the merge according to the following "
307389
"prescription:"
308-
msgstr ""
390+
msgstr "然而,通常必須根據以下規定來計算合併:"
309391

310392
#: ../../howto/mro.rst:188
393+
#, fuzzy
311394
msgid ""
312395
"*take the head of the first list, i.e L[B1][0]; if this head is not in the "
313396
"tail of any of the other lists, then add it to the linearization of C and "
@@ -317,42 +400,54 @@ msgid ""
317400
"this case, it is impossible to construct the merge, Python 2.3 will refuse "
318401
"to create the class C and will raise an exception.*"
319402
msgstr ""
403+
"*取第一個清單的頭部,即L[B1][0];如果這個頭不在任何其他串列的尾部,則將其新增"
404+
"到 C 的線性化中,並將其從合併的串列中刪除,否則請查看下一個串列的頭並取出它,"
405+
"如果它是一個好頭。然後重複操作,直到所有的類別都被移除或無法找到好的頭。在這"
406+
"種情況下,不可能建構合併,Python 2.3 將拒絕建立類別 C 並引發例外。"
320407

321408
#: ../../howto/mro.rst:197
409+
#, fuzzy
322410
msgid ""
323411
"This prescription ensures that the merge operation *preserves* the ordering, "
324412
"if the ordering can be preserved. On the other hand, if the order cannot be "
325413
"preserved (as in the example of serious order disagreement discussed above) "
326414
"then the merge cannot be computed."
327415
msgstr ""
416+
"如果可以保留順序,則此規定可確保合併操作「保留」順序。另一方面,如果無法保留"
417+
"順序(如上面討論的嚴重順序不一致的範例),則無法計算合併。"
328418

329419
#: ../../howto/mro.rst:202
420+
#, fuzzy
330421
msgid ""
331422
"The computation of the merge is trivial if C has only one parent (single "
332423
"inheritance); in this case::"
333424
msgstr ""
425+
"如果 C 只有一個父級(單繼承),則合併的計算是微不足道的;在這種情況下: ::"
334426

335427
#: ../../howto/mro.rst:205
336428
msgid "L[C(B)] = C + merge(L[B],B) = C + L[B]"
337429
msgstr "L[C(B)] = C + merge(L[B],B) = C + L[B]"
338430

339431
#: ../../howto/mro.rst:207
432+
#, fuzzy
340433
msgid ""
341434
"However, in the case of multiple inheritance things are more cumbersome and "
342435
"I don't expect you can understand the rule without a couple of examples ;-)"
343436
msgstr ""
437+
"但是,在多重繼承的情況下,事情會更加麻煩,我不希望你在沒有幾個示例的情況下理"
438+
"解該規則;-)"
344439

345440
#: ../../howto/mro.rst:212
346441
msgid "Examples"
347442
msgstr "範例"
348443

349444
#: ../../howto/mro.rst:214
350445
msgid "First example. Consider the following hierarchy:"
351-
msgstr ""
446+
msgstr "第一個例子,請參考以下層次結構:"
352447

353448
#: ../../howto/mro.rst:224
354449
msgid "In this case the inheritance graph can be drawn as:"
355-
msgstr ""
450+
msgstr "在這種情況下,繼承圖可以繪製為:"
356451

357452
#: ../../howto/mro.rst:226
358453
msgid ""
@@ -378,10 +473,32 @@ msgid ""
378473
"Level 0 0 | A | (more specialized)\n"
379474
" ---"
380475
msgstr ""
476+
" 6\n"
477+
" ---\n"
478+
"Level 3 | O | (more general)\n"
479+
" / --- \\\n"
480+
" / | \\ |\n"
481+
" / | \\ |\n"
482+
" / | \\ |\n"
483+
" --- --- --- |\n"
484+
"Level 2 3 | D | 4| E | | F | 5 |\n"
485+
" --- --- --- |\n"
486+
" \\ \\ _ / | |\n"
487+
" \\ / \\ _ | |\n"
488+
" \\ / \\ | |\n"
489+
" --- --- |\n"
490+
"Level 1 1 | B | | C | 2 |\n"
491+
" --- --- |\n"
492+
" \\ / |\n"
493+
" \\ / \\ /\n"
494+
" ---\n"
495+
"Level 0 0 | A | (more specialized)\n"
496+
" ---"
381497

382498
#: ../../howto/mro.rst:251
499+
#, fuzzy
383500
msgid "The linearizations of O,D,E and F are trivial::"
384-
msgstr ""
501+
msgstr "O、D、E 和 F 的線性化很簡單: ::"
385502

386503
#: ../../howto/mro.rst:253
387504
msgid ""
@@ -390,31 +507,41 @@ msgid ""
390507
"L[E] = E O\n"
391508
"L[F] = F O"
392509
msgstr ""
510+
"L[O] = O\n"
511+
"L[D] = D O\n"
512+
"L[E] = E O\n"
513+
"L[F] = F O"
393514

394515
#: ../../howto/mro.rst:258
516+
#, fuzzy
395517
msgid "The linearization of B can be computed as::"
396-
msgstr ""
518+
msgstr "B 的線性化可以計算為: ::"
397519

398520
#: ../../howto/mro.rst:260
399521
msgid "L[B] = B + merge(DO, EO, DE)"
400522
msgstr "L[B] = B + merge(DO, EO, DE)"
401523

402524
#: ../../howto/mro.rst:262
525+
#, fuzzy
403526
msgid ""
404527
"We see that D is a good head, therefore we take it and we are reduced to "
405528
"compute ``merge(O,EO,E)``. Now O is not a good head, since it is in the "
406529
"tail of the sequence EO. In this case the rule says that we have to skip to "
407530
"the next sequence. Then we see that E is a good head; we take it and we are "
408531
"reduced to compute ``merge(O,O)`` which gives O. Therefore::"
409532
msgstr ""
533+
"我們看到 D 是一個好頭,因此我們接受它並簡化為計算「merge(O,EO,E)」。 現在 O "
534+
"不是一個好的頭,因為它位於序列 EO 的尾部。在這種情況下,規則規定我們必須跳到"
535+
"下一個序列。那我們看到E是一個好頭;我們接受它並簡化為計算“merge(O,O)”,它給"
536+
"出 O。因此: ::"
410537

411538
#: ../../howto/mro.rst:268
412539
msgid "L[B] = B D E O"
413540
msgstr "L[B] = B D E O"
414541

415542
#: ../../howto/mro.rst:270
416543
msgid "Using the same procedure one finds::"
417-
msgstr ""
544+
msgstr "使用相同的程序可以發現: ::"
418545

419546
#: ../../howto/mro.rst:272
420547
msgid ""
@@ -430,7 +557,7 @@ msgstr ""
430557

431558
#: ../../howto/mro.rst:277
432559
msgid "Now we can compute::"
433-
msgstr ""
560+
msgstr "現在我們可以計算出: ::"
434561

435562
#: ../../howto/mro.rst:279
436563
msgid ""
@@ -451,25 +578,31 @@ msgstr ""
451578
" = A B C D E F O"
452579

453580
#: ../../howto/mro.rst:287
581+
#, fuzzy
454582
msgid ""
455583
"In this example, the linearization is ordered in a pretty nice way according "
456584
"to the inheritance level, in the sense that lower levels (i.e. more "
457585
"specialized classes) have higher precedence (see the inheritance graph). "
458586
"However, this is not the general case."
459587
msgstr ""
588+
"在此範例中,線性化根據繼承層級以非常好的方式排序,從某種意義上說,較低層級"
589+
"(即更專業的類別)具有更高的優先權(請參閱繼承圖)。然而,這不是一般情況。"
460590

461591
#: ../../howto/mro.rst:292
462592
msgid ""
463593
"I leave as an exercise for the reader to compute the linearization for my "
464594
"second example:"
465-
msgstr ""
595+
msgstr "第二個範例的線性化之計算我留給讀者當作練習:"
466596

467597
#: ../../howto/mro.rst:303
598+
#, fuzzy
468599
msgid ""
469-
"The only difference with the previous example is the change B(D,E) --> B(E,"
470-
"D); however even such a little modification completely changes the ordering "
471-
"of the hierarchy:"
600+
"The only difference with the previous example is the change B(D,E) --> "
601+
"B(E,D); however even such a little modification completely changes the "
602+
"ordering of the hierarchy:"
472603
msgstr ""
604+
"與上一個範例的唯一差異是更改 B(D,E) --> B(E,D);然而,即使這樣一點點修改也會完"
605+
"全改變層次結構的順序:"
473606

474607
#: ../../howto/mro.rst:307
475608
msgid ""
@@ -518,25 +651,34 @@ msgstr ""
518651
" ---"
519652

520653
#: ../../howto/mro.rst:332
654+
#, fuzzy
521655
msgid ""
522656
"Notice that the class E, which is in the second level of the hierarchy, "
523657
"precedes the class C, which is in the first level of the hierarchy, i.e. E "
524658
"is more specialized than C, even if it is in a higher level."
525659
msgstr ""
660+
"請注意,位於層次結構第二層的類別 E 位於位於層次結構第一層的類別 C 之前,即 E "
661+
"比 C 更專業,即使它位於更高的層級。"
526662

527663
#: ../../howto/mro.rst:336
664+
#, fuzzy
528665
msgid ""
529666
"A lazy programmer can obtain the MRO directly from Python 2.2, since in this "
530667
"case it coincides with the Python 2.3 linearization. It is enough to invoke "
531668
"the :meth:`~type.mro` method of class A:"
532669
msgstr ""
670+
"懶惰的程式設計師可以直接從 Python 2.2 取得 MRO,因為在這種情況下它與 Python "
671+
"2.3 線性化一致。呼叫 A 類別的 .mro() 方法就足夠了:"
533672

534673
#: ../../howto/mro.rst:345
674+
#, fuzzy
535675
msgid ""
536676
"Finally, let me consider the example discussed in the first section, "
537677
"involving a serious order disagreement. In this case, it is straightforward "
538678
"to compute the linearizations of O, X, Y, A and B:"
539679
msgstr ""
680+
"最後,讓我考慮第一節中討論的例子,其中涉及嚴重的順序分歧。在這種情況下,計算 "
681+
"O、X、Y、A 和 B 的線性化非常簡單:"
540682

541683
#: ../../howto/mro.rst:349
542684
msgid ""
@@ -553,10 +695,11 @@ msgstr ""
553695
"L[B] = B Y X O"
554696

555697
#: ../../howto/mro.rst:357
698+
#, fuzzy
556699
msgid ""
557700
"However, it is impossible to compute the linearization for a class C that "
558701
"inherits from A and B::"
559-
msgstr ""
702+
msgstr "然而,不可能計算繼承自 A 和 B 的類別 C 的線性化:"
560703

561704
#: ../../howto/mro.rst:360
562705
msgid ""
@@ -569,34 +712,43 @@ msgstr ""
569712
" = C + A + B + merge(XYO, YXO)"
570713

571714
#: ../../howto/mro.rst:364
715+
#, fuzzy
572716
msgid ""
573717
"At this point we cannot merge the lists XYO and YXO, since X is in the tail "
574718
"of YXO whereas Y is in the tail of XYO: therefore there are no good heads "
575719
"and the C3 algorithm stops. Python 2.3 raises an error and refuses to "
576720
"create the class C."
577721
msgstr ""
722+
"此時我們無法合併清單 XYO 和 YXO,因為 X 位於 YXO 的尾部,而 Y 位於 XYO 的尾"
723+
"部:因此沒有好的頭並且 C3 演演算法停止。Python 2.3 引發錯誤並拒絕建立 C 類"
724+
"別。"
578725

579726
#: ../../howto/mro.rst:370
580727
msgid "Bad Method Resolution Orders"
581-
msgstr ""
728+
msgstr "不良的方法解析順序"
582729

583730
#: ../../howto/mro.rst:372
731+
#, fuzzy
584732
msgid ""
585733
"A MRO is *bad* when it breaks such fundamental properties as local "
586734
"precedence ordering and monotonicity. In this section, I will show that "
587735
"both the MRO for classic classes and the MRO for new style classes in Python "
588736
"2.2 are bad."
589737
msgstr ""
738+
"當 MRO 破壞了局部優先順序和單調性等基本屬性時,它就是「壞」的。在本節中,我將"
739+
"展示 Python 2.2 中經典類別的 MRO 和新樣式類別的 MRO 都很糟糕。"
590740

591741
#: ../../howto/mro.rst:377
742+
#, fuzzy
592743
msgid ""
593744
"It is easier to start with the local precedence ordering. Consider the "
594745
"following example:"
595-
msgstr ""
746+
msgstr "從區域優先順序開始會更容易。考慮以下範例:"
596747

597748
#: ../../howto/mro.rst:384
749+
#, fuzzy
598750
msgid "with inheritance diagram"
599-
msgstr ""
751+
msgstr "附有繼承圖"
600752

601753
#: ../../howto/mro.rst:386
602754
msgid ""
@@ -610,47 +762,71 @@ msgid ""
610762
"\n"
611763
" (buy eggs or spam ?)"
612764
msgstr ""
765+
" O\n"
766+
" |\n"
767+
"(buy spam) F\n"
768+
" | \\\n"
769+
" | E (buy eggs)\n"
770+
" | /\n"
771+
" G\n"
772+
"\n"
773+
" (buy eggs or spam ?)"
613774

614775
#: ../../howto/mro.rst:399
776+
#, fuzzy
615777
msgid ""
616778
"We see that class G inherits from F and E, with F *before* E: therefore we "
617-
"would expect the attribute *G.remember2buy* to be inherited by *F."
618-
"remember2buy* and not by *E.remember2buy*: nevertheless Python 2.2 gives"
779+
"would expect the attribute *G.remember2buy* to be inherited by "
780+
"*F.remember2buy* and not by *E.remember2buy*: nevertheless Python 2.2 gives"
619781
msgstr ""
782+
"我們看到類別 G 繼承自 F 和 E,其中 F *在* E 之前:因此我們期望屬性 "
783+
"*G.remember2buy* 由 *F.rembermer2buy* 繼承,而不是由 *E.remember2buy* 繼承:"
784+
"儘管如此,Python 2.2給出"
620785

621786
#: ../../howto/mro.rst:407
787+
#, fuzzy
622788
msgid ""
623789
"This is a breaking of local precedence ordering since the order in the local "
624790
"precedence list, i.e. the list of the parents of G, is not preserved in the "
625791
"Python 2.2 linearization of G::"
626792
msgstr ""
793+
"這是對局部優先順序的破壞,因為局部優先串列(即 G 的父級串列)中的順序未保留"
794+
"在 G 的 Python 2.2 線性化中: ::"
627795

628796
#: ../../howto/mro.rst:411
629797
msgid "L[G,P22]= G E F object # F *follows* E"
630-
msgstr "L[G,P22]= G E F object # F *follows* E"
798+
msgstr "L[G,P22]= G E F object # F *跟隨* E"
631799

632800
#: ../../howto/mro.rst:413
801+
#, fuzzy
633802
msgid ""
634803
"One could argue that the reason why F follows E in the Python 2.2 "
635804
"linearization is that F is less specialized than E, since F is the "
636805
"superclass of E; nevertheless the breaking of local precedence ordering is "
637806
"quite non-intuitive and error prone. This is particularly true since it is "
638807
"a different from old style classes:"
639808
msgstr ""
809+
"有人可能會說,在 Python 2.2 線性化中 F 跟隨 E 的原因是 F 不如 E 專業化,因為 "
810+
"F 是 E 的超類別;然而,破壞區域優先順序是相當不直觀且容易出錯的。這是特別正確"
811+
"的,因為它與舊式類別不同:"
640812

641813
#: ../../howto/mro.rst:425
642814
msgid ""
643815
"In this case the MRO is GFEF and the local precedence ordering is preserved."
644-
msgstr ""
816+
msgstr "在這種情況下,MRO 是 GFEF,並且保留區域優先順序。"
645817

646818
#: ../../howto/mro.rst:428
819+
#, fuzzy
647820
msgid ""
648821
"As a general rule, hierarchies such as the previous one should be avoided, "
649822
"since it is unclear if F should override E or vice-versa. Python 2.3 solves "
650823
"the ambiguity by raising an exception in the creation of class G, "
651824
"effectively stopping the programmer from generating ambiguous hierarchies. "
652825
"The reason for that is that the C3 algorithm fails when the merge::"
653826
msgstr ""
827+
"作為一般規則,應該避免像前一個這樣的層次結構,因為尚不清楚 F 是否應該覆蓋 E "
828+
"或反之亦然。 Python 2.3 透過在建立類別 G 時引發例外來解決歧義性,有效地阻止程"
829+
"式設計師產生歧義的層次結構。原因是 C3 演演算法在合併時失敗: ::"
654830

655831
#: ../../howto/mro.rst:435
656832
msgid "merge(FO,EFO,FE)"
@@ -660,14 +836,17 @@ msgstr "merge(FO,EFO,FE)"
660836
msgid ""
661837
"cannot be computed, because F is in the tail of EFO and E is in the tail of "
662838
"FE."
663-
msgstr ""
839+
msgstr "無法計算,因為 F 在 EFO 的尾部,而 E 在 FE 的尾部。"
664840

665841
#: ../../howto/mro.rst:440
842+
#, fuzzy
666843
msgid ""
667844
"The real solution is to design a non-ambiguous hierarchy, i.e. to derive G "
668845
"from E and F (the more specific first) and not from F and E; in this case "
669846
"the MRO is GEF without any doubt."
670847
msgstr ""
848+
"真正的解決方案是設計一個明確的層次結構,即從 E 和 F(更具體的第一個)導出 G,"
849+
"而不是從 F 和 E 導出;在這種情況下,MRO 毫無疑問就是 GEF。"
671850

672851
#: ../../howto/mro.rst:444
673852
msgid ""
@@ -680,55 +859,77 @@ msgid ""
680859
" G\n"
681860
" (eggs, no doubt)"
682861
msgstr ""
862+
" O\n"
863+
" |\n"
864+
" F (spam)\n"
865+
" / |\n"
866+
"(eggs) E |\n"
867+
" \\ |\n"
868+
" G\n"
869+
" (eggs, no doubt)"
683870

684871
#: ../../howto/mro.rst:456
872+
#, fuzzy
685873
msgid ""
686874
"Python 2.3 forces the programmer to write good hierarchies (or, at least, "
687875
"less error-prone ones)."
688876
msgstr ""
877+
"Python 2.3 迫使程式設計師寫出良好的層次結構(或至少是不容易出錯的層次結構)。"
689878

690879
#: ../../howto/mro.rst:459
880+
#, fuzzy
691881
msgid ""
692882
"On a related note, let me point out that the Python 2.3 algorithm is smart "
693883
"enough to recognize obvious mistakes, as the duplication of classes in the "
694884
"list of parents:"
695885
msgstr ""
886+
"在相關說明中,讓我指出 Python 2.3 演演算法足夠聰明,可以識別明顯的錯誤,例如"
887+
"父級串列中的類別重複:"
696888

697889
#: ../../howto/mro.rst:469
890+
#, fuzzy
698891
msgid ""
699892
"Python 2.2 (both for classic classes and new style classes) in this "
700893
"situation, would not raise any exception."
701894
msgstr ""
895+
"Python 2.2(無論是經典類別還是新式類別)在這種情況下都不會引發任何例外。"
702896

703897
#: ../../howto/mro.rst:472
898+
#, fuzzy
704899
msgid ""
705900
"Finally, I would like to point out two lessons we have learned from this "
706901
"example:"
707-
msgstr ""
902+
msgstr "最後,我想指出我們從這個例子中學到的兩個教訓:"
708903

709904
#: ../../howto/mro.rst:475
905+
#, fuzzy
710906
msgid ""
711907
"despite the name, the MRO determines the resolution order of attributes, not "
712908
"only of methods;"
713-
msgstr ""
909+
msgstr "儘管名稱如此,MRO 決定了屬性的解析順序,而不僅僅是方法的解析順序;"
714910

715911
#: ../../howto/mro.rst:478
912+
#, fuzzy
716913
msgid ""
717914
"the default food for Pythonistas is spam ! (but you already knew that ;-)"
718-
msgstr ""
915+
msgstr "Pythonista 的預設食物是 spam!(但你已經知道了 ;-)"
719916

720917
#: ../../howto/mro.rst:481
918+
#, fuzzy
721919
msgid ""
722920
"Having discussed the issue of local precedence ordering, let me now consider "
723921
"the issue of monotonicity. My goal is to show that neither the MRO for "
724922
"classic classes nor that for Python 2.2 new style classes is monotonic."
725923
msgstr ""
924+
"討論完局部優先順序問題後,現在讓我考慮單調性問題。我的目標是表明經典類別的 "
925+
"MRO 和 Python 2.2 新樣式類別的 MRO 都不是單調的。"
726926

727927
#: ../../howto/mro.rst:486
928+
#, fuzzy
728929
msgid ""
729930
"To prove that the MRO for classic classes is non-monotonic is rather "
730931
"trivial, it is enough to look at the diamond diagram:"
731-
msgstr ""
932+
msgstr "要證明經典類別的 MRO 是非單調的相當簡單,看一下菱形圖就夠了:"
732933

733934
#: ../../howto/mro.rst:489
734935
msgid ""
@@ -750,7 +951,7 @@ msgstr ""
750951

751952
#: ../../howto/mro.rst:500
752953
msgid "One easily discerns the inconsistency::"
753-
msgstr ""
954+
msgstr "可以很容易地辨別出這種不一致: ::"
754955

755956
#: ../../howto/mro.rst:502
756957
msgid ""
@@ -759,36 +960,47 @@ msgid ""
759960
msgstr ""
760961

761962
#: ../../howto/mro.rst:505
963+
#, fuzzy
762964
msgid ""
763965
"On the other hand, there are no problems with the Python 2.2 and 2.3 MROs, "
764966
"they give both::"
765-
msgstr ""
967+
msgstr "另一方面,Python 2.2 和 2.3 MRO 沒有問題,它們同時提供: ::"
766968

767969
#: ../../howto/mro.rst:508
768970
msgid "L[D] = D A B C"
769971
msgstr "L[D] = D A B C"
770972

771973
#: ../../howto/mro.rst:510
974+
#, fuzzy
772975
msgid ""
773976
"Guido points out in his essay [#]_ that the classic MRO is not so bad in "
774977
"practice, since one can typically avoids diamonds for classic classes. But "
775978
"all new style classes inherit from ``object``, therefore diamonds are "
776979
"unavoidable and inconsistencies shows up in every multiple inheritance graph."
777980
msgstr ""
981+
"Guido 在他的文章 [#]_ 中指出,經典的 MRO 在實踐中並沒有那麼糟糕,因為人們通常"
982+
"可以避免經典類別的鑽石。但是所有新樣式類別都繼承自 ``object``,因此菱形是不可"
983+
"避免的,並且每個多重繼承圖中都會出現不一致。"
778984

779985
#: ../../howto/mro.rst:516
986+
#, fuzzy
780987
msgid ""
781988
"The MRO of Python 2.2 makes breaking monotonicity difficult, but not "
782989
"impossible. The following example, originally provided by Samuele Pedroni, "
783990
"shows that the MRO of Python 2.2 is non-monotonic:"
784991
msgstr ""
992+
"Python 2.2 的 MRO 讓打破單調變得困難,但並非不可能。以下範例最初由 Samuele "
993+
"Pedroni 提供,顯示 Python 2.2 的 MRO 是非單調的:"
785994

786995
#: ../../howto/mro.rst:530
996+
#, fuzzy
787997
msgid ""
788998
"Here are the linearizations according to the C3 MRO (the reader should "
789999
"verify these linearizations as an exercise and draw the inheritance "
7901000
"diagram ;-) ::"
7911001
msgstr ""
1002+
"以下是根據 C3 MRO 的線性化(讀者應該驗證這些線性化作為練習並繪製繼承"
1003+
"圖 ;-): ::"
7921004

7931005
#: ../../howto/mro.rst:534
7941006
msgid ""
@@ -813,16 +1025,20 @@ msgstr ""
8131025
"L[Z] = Z K1 K2 K3 D A B C E O"
8141026

8151027
#: ../../howto/mro.rst:544
1028+
#, fuzzy
8161029
msgid ""
8171030
"Python 2.2 gives exactly the same linearizations for A, B, C, D, E, K1, K2 "
8181031
"and K3, but a different linearization for Z::"
8191032
msgstr ""
1033+
"Python 2.2 為 A、B、C、D、E、K1、K2 和 K3 提供了完全相同的線性化,但為 Z 提供"
1034+
"了不同的線性化: ::"
8201035

8211036
#: ../../howto/mro.rst:547
8221037
msgid "L[Z,P22] = Z K1 K3 A K2 D B C E O"
8231038
msgstr "L[Z,P22] = Z K1 K3 A K2 D B C E O"
8241039

8251040
#: ../../howto/mro.rst:549
1041+
#, fuzzy
8261042
msgid ""
8271043
"It is clear that this linearization is *wrong*, since A comes before D "
8281044
"whereas in the linearization of K3 A comes *after* D. In other words, in K3 "
@@ -834,12 +1050,19 @@ msgid ""
8341050
"the linearization of Z K2 *follows* K3. These problems explain why the 2.2 "
8351051
"rule has been dismissed in favor of the C3 rule."
8361052
msgstr ""
1053+
"很明顯,這種線性化是\\ *錯誤的*,因為 A 在 D 之前,而在 K3 的線性化中,A 在 "
1054+
"D 之後。但在 Z 中,仍然是 K3 的子類別,A 衍生的方法覆蓋 D 衍生的方法!這是違"
1055+
"反單調性的。此外,Z 的 Python 2.2 線性化也與局部優先權順序不一致,因為類別 Z "
1056+
"的局部優先權串列是 [K1, K2, K3](K2 在 K3 之前),而在Z 的線性化中,K2 *跟隨"
1057+
"* K3。這些問題解釋了為什麼 2.2 規則被 C3 規則所取代。"
8371058

8381059
#: ../../howto/mro.rst:561
1060+
#, fuzzy
8391061
msgid "The end"
840-
msgstr ""
1062+
msgstr "結束"
8411063

8421064
#: ../../howto/mro.rst:563
1065+
#, fuzzy
8431066
msgid ""
8441067
"This section is for the impatient reader, who skipped all the previous "
8451068
"sections and jumped immediately to the end. This section is for the lazy "
@@ -852,6 +1075,12 @@ msgid ""
8521075
"the last line to play with the various examples I have discussed in this "
8531076
"paper.::"
8541077
msgstr ""
1078+
"本節是為不耐煩的讀者準備的,他們跳過了前面的所有部分並立即跳到了最後。本節也"
1079+
"適合懶惰的程式設計師,他們不想鍛鍊她/他的大腦。最後,它是為那些傲慢的程式設計"
1080+
"師準備的,否則他/她就不會閱讀關於多重繼承層次結構中 C3 方法解析順序的論"
1081+
"文;-) 這三個優點放在一起(而不是單獨)值得獎勵:獎品是一個簡短的Python 2.2 "
1082+
"腳本,它允許你計算 2.3 MRO,而不會給你的大腦帶來風險。只需更改最後一行即可使"
1083+
"用我在本文中討論的各種範例。 ::"
8551084

8561085
#: ../../howto/mro.rst:574
8571086
msgid ""
@@ -940,32 +1169,41 @@ msgid ""
9401169
msgstr ""
9411170

9421171
#: ../../howto/mro.rst:656
1172+
#, fuzzy
9431173
msgid "That's all folks,"
944-
msgstr ""
1174+
msgstr "以上,"
9451175

9461176
#: ../../howto/mro.rst:658
1177+
#, fuzzy
9471178
msgid "enjoy !"
948-
msgstr ""
1179+
msgstr "享受!"
9491180

9501181
#: ../../howto/mro.rst:662
9511182
msgid "Resources"
952-
msgstr ""
1183+
msgstr "資源"
9531184

9541185
#: ../../howto/mro.rst:664
9551186
msgid ""
9561187
"The thread on python-dev started by Samuele Pedroni: https://mail.python.org/"
9571188
"pipermail/python-dev/2002-October/029035.html"
9581189
msgstr ""
1190+
"Samuele Pedroni 發起的 python-dev 主題討論:https://mail.python.org/"
1191+
"pipermail/python-dev/2002-October/029035.html"
9591192

9601193
#: ../../howto/mro.rst:667
9611194
msgid ""
962-
"The paper *A Monotonic Superclass Linearization for Dylan*: https://doi."
963-
"org/10.1145/236337.236343"
1195+
"The paper *A Monotonic Superclass Linearization for Dylan*: https://doi.org/"
1196+
"10.1145/236337.236343"
9641197
msgstr ""
1198+
"論文 *A Monotonic Superclass Linearization for Dylan*: https://doi.org/"
1199+
"10.1145/236337.236343"
9651200

9661201
#: ../../howto/mro.rst:670
9671202
msgid ""
9681203
"Guido van Rossum's essay, *Unifying types and classes in Python 2.2*: "
9691204
"https://web.archive.org/web/20140210194412/http://www.python.org/download/"
9701205
"releases/2.2.2/descrintro"
9711206
msgstr ""
1207+
"Guido van Rossum 的文章,*Unifying types and classes in Python 2.2*:https://"
1208+
"web.archive.org/web/20140210194412/http://www.python.org/download/releases/"
1209+
"2.2.2/descrintro"

0 commit comments

Comments
 (0)
Please sign in to comment.