Skip to content

Commit e2d202d

Browse files
committed
Update NewType Section
1 parent eaccd60 commit e2d202d

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

library/typing.po

+25-5
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ msgstr ""
88
"Project-Id-Version: Python 3.12\n"
99
"Report-Msgid-Bugs-To: \n"
1010
"POT-Creation-Date: 2023-10-11 17:13+0000\n"
11-
"PO-Revision-Date: 2023-09-05 14:49+0800\n"
11+
"PO-Revision-Date: 2023-10-31 23:08+0800\n"
1212
"Last-Translator: RockLeon <therockleona@gmail.com>\n"
1313
"Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-"
1414
"tw)\n"
@@ -17,7 +17,7 @@ msgstr ""
1717
"Content-Type: text/plain; charset=UTF-8\n"
1818
"Content-Transfer-Encoding: 8bit\n"
1919
"Plural-Forms: nplurals=1; plural=0;\n"
20-
"X-Generator: Poedit 3.3.1\n"
20+
"X-Generator: Poedit 3.4.1\n"
2121

2222
#: ../../library/typing.rst:3
2323
msgid ":mod:`typing` --- Support for type hints"
@@ -357,13 +357,15 @@ msgstr "NewType"
357357

358358
#: ../../library/typing.rst:179
359359
msgid "Use the :class:`NewType` helper to create distinct types::"
360-
msgstr ""
360+
msgstr "使用 :class:`NewType` 工具 (helper) 建立獨特型別: ::"
361361

362362
#: ../../library/typing.rst:186
363363
msgid ""
364364
"The static type checker will treat the new type as if it were a subclass of "
365365
"the original type. This is useful in helping catch logical errors::"
366366
msgstr ""
367+
"若它是原本型別的子類別,靜態型別檢查器會將其視為一個新的型別。這對於幫助擷取"
368+
"邏輯性錯誤非常有用: ::"
367369

368370
#: ../../library/typing.rst:198
369371
msgid ""
@@ -372,6 +374,9 @@ msgid ""
372374
"pass in a ``UserId`` wherever an ``int`` might be expected, but will prevent "
373375
"you from accidentally creating a ``UserId`` in an invalid way::"
374376
msgstr ""
377+
"你依然可以在型別 `UserId`` 的變數中,執行所有 ``int`` 的操作。這讓你可以在預"
378+
"期是 ``int`` 的情況之下傳遞一個 ``UserId``,這會預防你意外使用無效的方法建立"
379+
"一個 ``UserId``: ::"
375380

376381
#: ../../library/typing.rst:206
377382
msgid ""
@@ -381,26 +386,33 @@ msgid ""
381386
"it. That means the expression ``Derived(some_value)`` does not create a new "
382387
"class or introduce much overhead beyond that of a regular function call."
383388
msgstr ""
389+
"注意這只會透過靜態型別檢查器強制檢查。在執行環境 (runtime) 中,敘述句 "
390+
"(statement) ``Derived = NewType('Derived', Base)`` 會使 ``Derived`` 成為一個 "
391+
"callable(可呼叫物件),會立即回傳任何你傳遞的引數。這意味著 expression (運"
392+
"算式)``Derived(some_value)`` 不會建立一個新的類別或過度引入原有的涵式呼叫。"
384393

385394
#: ../../library/typing.rst:212
386395
msgid ""
387396
"More precisely, the expression ``some_value is Derived(some_value)`` is "
388397
"always true at runtime."
389398
msgstr ""
399+
"更精確地說,expression ``some_value is Derived(some_value)`` 在執行環境時永遠"
400+
"為 true。"
390401

391402
#: ../../library/typing.rst:215
392403
msgid "It is invalid to create a subtype of ``Derived``::"
393-
msgstr ""
404+
msgstr "這會無法建立一個 ``Derived`` 的子型別: ::"
394405

395406
#: ../../library/typing.rst:224
396407
msgid ""
397408
"However, it is possible to create a :class:`NewType` based on a 'derived' "
398409
"``NewType``::"
399410
msgstr ""
411+
"無論如何,這有辦法基於 'derived' ``NewType`` 建立一個 :class:`NewType`: ::"
400412

401413
#: ../../library/typing.rst:232
402414
msgid "and typechecking for ``ProUserId`` will work as expected."
403-
msgstr ""
415+
msgstr "以及針對 ``ProUserId`` 的型別檢查會如期運作。"
404416

405417
#: ../../library/typing.rst:234
406418
msgid "See :pep:`484` for more details."
@@ -413,6 +425,9 @@ msgid ""
413425
"checker treat ``Alias`` as being *exactly equivalent* to ``Original`` in all "
414426
"cases. This is useful when you want to simplify complex type signatures."
415427
msgstr ""
428+
"請記得使用型別別名是宣告兩種型別是互相\\*相等*\\的。使用 ``type Alias = "
429+
"Original`` 則會讓靜態型別檢查器在任何情況之下將 ``Alias`` 視為與 "
430+
"``Original`` \\*完全相等*\\。這當你想把複雜的型別簽名進行簡化時,非常好用。"
416431

417432
#: ../../library/typing.rst:243
418433
msgid ""
@@ -423,6 +438,11 @@ msgid ""
423438
"``Derived`` is expected. This is useful when you want to prevent logic "
424439
"errors with minimal runtime cost."
425440
msgstr ""
441+
"相反的,``NewType`` 宣告一個型別會是另外一種型別的子類別。使用 ``Derived = "
442+
"NewType('Derived', Original)`` 會使靜態型別檢查器將 ``Derived`` 視為 "
443+
"``Original`` 的子類別,也意味著一個型別為 ``Original`` 的值,不能被使用在任何"
444+
"預期接收到型別 ``Derived`` 的值的區域。這當你想用最小的執行環境成本 (runtime "
445+
"cost) 預防邏輯性錯誤而言,非常有用。"
426446

427447
#: ../../library/typing.rst:252
428448
msgid ""

0 commit comments

Comments
 (0)