8000 Update `library/typing` by rockleona · Pull Request #691 · python/python-docs-zh-tw · GitHub
[go: up one dir, main page]

Skip to content

Update library/typing #691

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Nov 6, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions library/typing.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgstr ""
"Project-Id-Version: Python 3.12\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2023-10-11 17:13+0000\n"
"PO-Revision-Date: 2023-09-05 14:49+0800\n"
"PO-Revision-Date: 2023-10-31 23:08+0800\n"
"Last-Translator: RockLeon <therockleona@gmail.com>\n"
"Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-"
"tw)\n"
Expand All @@ -17,7 +17,7 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=0;\n"
"X-Generator: Poedit 3.3.1\n"
"X-Generator: Poedit 3.4.1\n"

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

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

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

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

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

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

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

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

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

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

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

#: ../../library/typing.rst:252
msgid ""
Expand Down
0