diff --git a/howto/annotations.po b/howto/annotations.po index bef59517aa7..193d172eda0 100644 --- a/howto/annotations.po +++ b/howto/annotations.po @@ -7,15 +7,15 @@ msgstr "" "Project-Id-Version: Python 3.14\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2026-01-22 16:55+0000\n" -"PO-Revision-Date: 2023-11-08 23:11+0800\n" -"Last-Translator: rockleon \n" +"PO-Revision-Date: 2026-09-12 20:49+0800\n" +"Last-Translator: dy1012 \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" "tw)\n" "Language: zh_TW\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -"X-Generator: Poedit 3.4.1\n" +"X-Generator: Poedit 3.4.4\n" #: ../../howto/annotations.rst:5 msgid "Annotations Best Practices" @@ -60,8 +60,8 @@ msgstr "" msgid "" "Note that this document is specifically about working with " "``__annotations__``, not uses *for* annotations. If you're looking for " -"information on how to use \"type hints\" in your code, please see the :mod:" -"`typing` module." +"information on how to use \"type hints\" in your code, please see " +"the :mod:`typing` module." msgstr "" "請注意,本文件是特別說明 ``__annotations__`` 的使用,而非\\ *如何使用*\\ 註" "釋。如果你正在尋找如何在你的程式碼中使用「型別提示 (type hint)」的資訊,請查" @@ -73,11 +73,11 @@ msgstr "在 Python 3.10 及更高版本中存取物件的註釋字典" #: ../../howto/annotations.rst:35 msgid "" -"Python 3.10 adds a new function to the standard library: :func:`inspect." -"get_annotations`. In Python versions 3.10 through 3.13, calling this " -"function is the best practice for accessing the annotations dict of any " -"object that supports annotations. This function can also \"un-stringize\" " -"stringized annotations for you." +"Python 3.10 adds a new function to the standard " +"library: :func:`inspect.get_annotations`. In Python versions 3.10 through " +"3.13, calling this function is the best practice for accessing the " +"annotations dict of any object that supports annotations. This function can " +"also \"un-stringize\" stringized annotations for you." msgstr "" "Python 3.10 在標準函式庫中新增了一個新函式::func:`inspect.get_annotations`。" "在 Python 3.10 到 3.13,呼叫此函式是存取任何支援註釋的物件的註釋字典的最佳實" @@ -86,17 +86,20 @@ msgstr "" #: ../../howto/annotations.rst:42 msgid "" "In Python 3.14, there is a new :mod:`annotationlib` module with " -"functionality for working with annotations. This includes a :func:" -"`annotationlib.get_annotations` function, which supersedes :func:`inspect." -"get_annotations`." +"functionality for working with annotations. This includes " +"a :func:`annotationlib.get_annotations` function, which " +"supersedes :func:`inspect.get_annotations`." msgstr "" +"在 Python 3.14 中,新增了一個名為 :mod:`annotationlib` 的模組,具備處理註釋的" +"功能。其中包含一個名為 :func:`annotationlib.get_annotations` 的函式,該函式已" +"取代 :func:`inspect.get_annotations`。" #: ../../howto/annotations.rst:47 msgid "" "If for some reason :func:`inspect.get_annotations` isn't viable for your use " "case, you may access the ``__annotations__`` data member manually. Best " -"practice for this changed in Python 3.10 as well: as of Python 3.10, ``o." -"__annotations__`` is guaranteed to *always* work on Python functions, " +"practice for this changed in Python 3.10 as well: as of Python 3.10, " +"``o.__annotations__`` is guaranteed to *always* work on Python functions, " "classes, and modules. If you're certain the object you're examining is one " "of these three *specific* objects, you may simply use ``o.__annotations__`` " "to get at the object's annotations dict." @@ -109,11 +112,12 @@ msgstr "" #: ../../howto/annotations.rst:57 msgid "" -"However, other types of callables--for example, callables created by :func:" -"`functools.partial`--may not have an ``__annotations__`` attribute defined. " -"When accessing the ``__annotations__`` of a possibly unknown object, best " -"practice in Python versions 3.10 and newer is to call :func:`getattr` with " -"three arguments, for example ``getattr(o, '__annotations__', None)``." +"However, other types of callables--for example, callables created " +"by :func:`functools.partial`--may not have an ``__annotations__`` attribute " +"defined. When accessing the ``__annotations__`` of a possibly unknown " +"object, best practice in Python versions 3.10 and newer is to " +"call :func:`getattr` with three arguments, for example ``getattr(o, " +"'__annotations__', None)``." msgstr "" "但是,其他型別的 callable(可呼叫物件)(例如,由 :func:`functools.partial` " "建立的 callable)可能沒有定義 ``__annotations__`` 屬性 (attribute)。當存取可" @@ -205,9 +209,9 @@ msgid "" msgstr "" "如果你正在檢查的物件是一個類別 (``isinstance(o, type)``),你的程式碼將必須有" "一個單獨的程式碼路徑。在這種情況下,最佳實踐依賴 Python 3.9 及之前版本的實作" -"細節 (implementation detail):如果一個類別定義了註釋,它們將儲存在該類別的 :" -"attr:`~type.__dict__` 字典中。由於類別可能定義了註釋,也可能沒有定義,因此最" -"佳實踐是在類別字典上呼叫 :meth:`~dict.get` 方法。" +"細節 (implementation detail):如果一個類別定義了註釋,它們將儲存在該類別" +"的 :attr:`~type.__dict__` 字典中。由於類別可能定義了註釋,也可能沒有定義,因" +"此最佳實踐是在類別字典上呼叫 :meth:`~dict.get` 方法。" #: ../../howto/annotations.rst:114 msgid "" @@ -233,21 +237,21 @@ msgstr "" #: ../../howto/annotations.rst:123 msgid "" "After running this code, ``ann`` should be either a dictionary or ``None``. " -"You're encouraged to double-check the type of ``ann`` using :func:" -"`isinstance` before further examination." +"You're encouraged to double-check the type of ``ann`` " +"using :func:`isinstance` before further examination." msgstr "" "運行此程式碼後,``ann`` 應該是字典或 ``None``。我們鼓勵你在進一步檢查之前使" "用 :func:`isinstance` 仔細檢查 ``ann`` 的型別。" #: ../../howto/annotations.rst:128 msgid "" -"Note that some exotic or malformed type objects may not have a :attr:`~type." -"__dict__` attribute, so for extra safety you may also wish to use :func:" -"`getattr` to access :attr:`!__dict__`." +"Note that some exotic or malformed type objects may not have " +"a :attr:`~type.__dict__` attribute, so for extra safety you may also wish to " +"use :func:`getattr` to access :attr:`!__dict__`." msgstr "" -"請注意,某些外來 (exotic) 或格式錯誤 (malform) 的型別物件可能沒有 :attr:" -"`~type.__dict__` 屬性,因此為了額外的安全,你可能還希望使用 :func:`getattr` " -"來存取 :attr:`!__dict__`。" +"請注意,某些外來 (exotic) 或格式錯誤 (malform) 的型別物件可能沒" +"有 :attr:`~type.__dict__` 屬性,因此為了額外的安全,你可能還希望使" +"用 :func:`getattr` 來存取 :attr:`!__dict__`。" #: ../../howto/annotations.rst:134 msgid "Manually Un-Stringizing Stringized Annotations" @@ -265,14 +269,15 @@ msgstr "" #: ../../howto/annotations.rst:142 msgid "" -"If you're using Python 3.9 or older, or if for some reason you can't use :" -"func:`inspect.get_annotations`, you'll need to duplicate its logic. You're " -"encouraged to examine the implementation of :func:`inspect.get_annotations` " -"in the current Python version and follow a similar approach." +"If you're using Python 3.9 or older, or if for some reason you can't " +"use :func:`inspect.get_annotations`, you'll need to duplicate its logic. " +"You're encouraged to examine the implementation " +"of :func:`inspect.get_annotations` in the current Python version and follow " +"a similar approach." msgstr "" -"如果你使用的是 Python 3.9 或更早版本,或者由於某種原因你無法使用 :func:" -"`inspect.get_annotations`,則需要複製其邏輯。我們鼓勵你檢查目前 Python 版本" -"中 :func:`inspect.get_annotations` 的實作並遵循類似的方法。" +"如果你使用的是 Python 3.9 或更早版本,或者由於某種原因你無法使" +"用 :func:`inspect.get_annotations`,則需要複製其邏輯。我們鼓勵你檢查目前 " +"Python 版本中 :func:`inspect.get_annotations` 的實作並遵循類似的方法。" #: ../../howto/annotations.rst:148 msgid "" @@ -282,8 +287,8 @@ msgstr "簡而言之,如果你希望評估任意物件 ``o`` 上的字串化 #: ../../howto/annotations.rst:151 msgid "" -"If ``o`` is a module, use ``o.__dict__`` as the ``globals`` when calling :" -"func:`eval`." +"If ``o`` is a module, use ``o.__dict__`` as the ``globals`` when " +"calling :func:`eval`." msgstr "" "如果 ``o`` 是一個模組,則在呼叫 :func:`eval` 時使用 ``o.__dict__`` 作為\\ ``" "全域變數``。" @@ -291,31 +296,32 @@ msgstr "" #: ../../howto/annotations.rst:153 msgid "" "If ``o`` is a class, use ``sys.modules[o.__module__].__dict__`` as the " -"``globals``, and ``dict(vars(o))`` as the ``locals``, when calling :func:" -"`eval`." +"``globals``, and ``dict(vars(o))`` as the ``locals``, when " +"calling :func:`eval`." msgstr "" -"如果 ``o`` 是一個類別,當呼叫 :func:`eval` 時,則使用 ``sys.modules[o." -"__module__].__dict__`` 作為\\ ``全域變數``,使用 ``dict(vars(o))`` 作為\\ ``" -"區域變數``。" +"如果 ``o`` 是一個類別,當呼叫 :func:`eval` 時,則使用 " +"``sys.modules[o.__module__].__dict__`` 作為\\ ``全域變數``,使用 " +"``dict(vars(o))`` 作為\\ ``區域變數``。" #: ../../howto/annotations.rst:156 msgid "" -"If ``o`` is a wrapped callable using :func:`functools.update_wrapper`, :func:" -"`functools.wraps`, or :func:`functools.partial`, iteratively unwrap it by " -"accessing either ``o.__wrapped__`` or ``o.func`` as appropriate, until you " -"have found the root unwrapped function." +"If ``o`` is a wrapped callable " +"using :func:`functools.update_wrapper`, :deco:`functools.wraps`, " +"or :func:`functools.partial`, iteratively unwrap it by accessing either " +"``o.__wrapped__`` or ``o.func`` as appropriate, until you have found the " +"root unwrapped function." msgstr "" "如果 ``o`` 是使用 :func:`functools.update_wrapper`、:func:`functools.wraps` " -"或 :func:`functools.partial` 包裝的 callable ,請依據需求,透過存取 ``o." -"__wrapped__`` 或 ``o.func`` 來疊代解開它,直到找到根解包函式。" +"或 :func:`functools.partial` 包裝的 callable ,請依據需求,透過存取 " +"``o.__wrapped__`` 或 ``o.func`` 來疊代解開它,直到找到根解包函式。" #: ../../howto/annotations.rst:160 msgid "" -"If ``o`` is a callable (but not a class), use :attr:`o.__globals__ ` as the globals when calling :func:`eval`." +"If ``o`` is a callable (but not a class), use :attr:`o.__globals__ " +"` as the globals when calling :func:`eval`." msgstr "" -"如果 ``o`` 是 callable(但不是類別),則在呼叫 :func:`eval` 時使用 :attr:`o." -"__globals__ ` 作為全域變數。" +"如果 ``o`` 是 callable(但不是類別),則在呼叫 :func:`eval` 時使" +"用 :attr:`o.__globals__ ` 作為全域變數。" #: ../../howto/annotations.rst:164 msgid "" @@ -338,8 +344,8 @@ msgstr "" #: ../../howto/annotations.rst:173 msgid "" -"Definitions that aren't needed at runtime, only imported when :const:`typing." -"TYPE_CHECKING` is true." +"Definitions that aren't needed at runtime, only imported " +"when :const:`typing.TYPE_CHECKING` is true." msgstr "" "Runtime 中不需要的定義,僅在 :const:`typing.TYPE_CHECKING` 為 true 時匯入。" @@ -376,9 +382,12 @@ msgstr "" #: ../../howto/annotations.rst:192 msgid "" "You should avoid accessing ``__annotations__`` directly on any object. " -"Instead, use :func:`annotationlib.get_annotations` (Python 3.14+) or :func:" -"`inspect.get_annotations` (Python 3.10+)." +"Instead, use :func:`annotationlib.get_annotations` (Python 3.14+) " +"or :func:`inspect.get_annotations` (Python 3.10+)." msgstr "" +"你應該避免直接存取物件的 ``__annotations__`` 。請改" +"用 :func:`annotationlib.get_annotations` (Python 3.14+) " +"或 :func:`inspect.get_annotations` (Python 3.10+)." #: ../../howto/annotations.rst:196 msgid "" @@ -477,18 +486,29 @@ msgstr "" msgid "" "If you use a class with a custom metaclass and access ``__annotations__`` on " "the class, you may observe unexpected behavior; see :pep:`749 <749#pep749-" -"metaclasses>` for some examples. You can avoid these quirks by using :func:" -"`annotationlib.get_annotations` on Python 3.14+ or :func:`inspect." -"get_annotations` on Python 3.10+. On earlier versions of Python, you can " -"avoid these bugs by accessing the annotations from the class's :attr:`~type." -"__dict__` (for example, ``cls.__dict__.get('__annotations__', None)``)." -msgstr "" +"metaclasses>` for some examples. You can avoid these quirks by " +"using :func:`annotationlib.get_annotations` on Python 3.14+ " +"or :func:`inspect.get_annotations` on Python 3.10+. On earlier versions of " +"Python, you can avoid these bugs by accessing the annotations from the " +"class's :attr:`~type.__dict__` (for example, " +"``cls.__dict__.get('__annotations__', None)``)." +msgstr "" +"如果你使用的類別具有自訂的元類別,並存取該類別的 ``__annotations__`` ,你可能" +"會觀察到出乎意料的行為;請查閱 :pep:`749 <749#pep749-metaclasses>` 的例子。你" +"可以在Python 3.14+ 使用 :func:`annotationlib.get_annotations` 或者在 Python " +"3.10+ 使用 :func:`inspect.get_annotations` 來避免這些問題。在更早期的版本,你" +"可以存取類別的 :attr:`~type.__dict__` 來避免這些問題。(例如:" +"``cls.__dict__.get(‘__annotations__’, None)`` )" #: ../../howto/annotations.rst:253 msgid "" "In some versions of Python, instances of classes may have an " "``__annotations__`` attribute. However, this is not supported functionality. " "If you need the annotations of an instance, you can use :func:`type` to " -"access its class (for example, ``annotationlib." -"get_annotations(type(myinstance))`` on Python 3.14+)." +"access its class (for example, " +"``annotationlib.get_annotations(type(myinstance))`` on Python 3.14+)." msgstr "" +"在某些 Python 版本中,類別實例可能會帶有 ``__annotations__`` 的屬性,但這並非" +"受支援的功能。如果你需要取得實例的註釋,可以用 :func:`type` 來存取實例的類別" +"(例如在 Python 3.14+ 中使用 " +"``annotationlib.get_annotations(type(myinstance))`` )."