From 5df3d65c16ee785ebe795454cff9e7eecf3c6da8 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 13 Mar 2026 17:07:51 +0000 Subject: [PATCH 1/2] sync with cpython c3ea6c29 --- library/stdtypes.po | 696 ++++++++++++++++++++-------------------- library/threadsafety.po | 167 +++++++++- tutorial/errors.po | 146 ++++----- 3 files changed, 589 insertions(+), 420 deletions(-) diff --git a/library/stdtypes.po b/library/stdtypes.po index 1b5145c9cda..12e088e8f99 100644 --- a/library/stdtypes.po +++ b/library/stdtypes.po @@ -9,7 +9,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.14\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2026-03-12 00:16+0000\n" +"POT-Creation-Date: 2026-03-13 17:06+0000\n" "PO-Revision-Date: 2022-06-12 15:22+0800\n" "Last-Translator: Matt Wang \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" @@ -7522,11 +7522,17 @@ msgid "" "*elem*." msgstr "" -#: ../../library/stdtypes.rst:5222 +#: ../../library/stdtypes.rst:5220 +msgid "" +"For detailed information on thread-safety guarantees for :class:`set` " +"objects, see :ref:`thread-safety-set`." +msgstr "" + +#: ../../library/stdtypes.rst:5227 msgid "Mapping Types --- :class:`dict`" msgstr "" -#: ../../library/stdtypes.rst:5232 +#: ../../library/stdtypes.rst:5237 msgid "" "A :term:`mapping` object maps :term:`hashable` values to arbitrary objects. " "Mappings are mutable objects. There is currently only one standard mapping " @@ -7535,7 +7541,7 @@ msgid "" "module.)" msgstr "" -#: ../../library/stdtypes.rst:5238 +#: ../../library/stdtypes.rst:5243 msgid "" "A dictionary's keys are *almost* arbitrary values. Values that are not :" "term:`hashable`, that is, values containing lists, dictionaries or other " @@ -7544,33 +7550,33 @@ msgid "" "and ``True``) can be used interchangeably to index the same dictionary entry." msgstr "" -#: ../../library/stdtypes.rst:5249 +#: ../../library/stdtypes.rst:5254 msgid "" "Return a new dictionary initialized from an optional positional argument and " "a possibly empty set of keyword arguments." msgstr "" -#: ../../library/stdtypes.rst:5252 +#: ../../library/stdtypes.rst:5257 msgid "Dictionaries can be created by several means:" msgstr "字典可以用數種方式建立:" -#: ../../library/stdtypes.rst:5254 +#: ../../library/stdtypes.rst:5259 msgid "" "Use a comma-separated list of ``key: value`` pairs within braces: ``{'jack': " "4098, 'sjoerd': 4127}`` or ``{4098: 'jack', 4127: 'sjoerd'}``" msgstr "" -#: ../../library/stdtypes.rst:5256 +#: ../../library/stdtypes.rst:5261 msgid "Use a dict comprehension: ``{}``, ``{x: x ** 2 for x in range(10)}``" msgstr "" -#: ../../library/stdtypes.rst:5257 +#: ../../library/stdtypes.rst:5262 msgid "" "Use the type constructor: ``dict()``, ``dict([('foo', 100), ('bar', " "200)])``, ``dict(foo=100, bar=200)``" msgstr "" -#: ../../library/stdtypes.rst:5260 +#: ../../library/stdtypes.rst:5265 msgid "" "If no positional argument is given, an empty dictionary is created. If a " "positional argument is given and it defines a ``keys()`` method, a " @@ -7583,7 +7589,7 @@ msgid "" "that key becomes the corresponding value in the new dictionary." msgstr "" -#: ../../library/stdtypes.rst:5270 +#: ../../library/stdtypes.rst:5275 msgid "" "If keyword arguments are given, the keyword arguments and their values are " "added to the dictionary created from the positional argument. If a key " @@ -7591,7 +7597,7 @@ msgid "" "the value from the positional argument." msgstr "" -#: ../../library/stdtypes.rst:5275 +#: ../../library/stdtypes.rst:5280 msgid "" "Dictionaries compare equal if and only if they have the same ``(key, " "value)`` pairs (regardless of ordering). Order comparisons ('<', '<=', '>=', " @@ -7600,7 +7606,7 @@ msgid "" "``{\"one\": 1, \"two\": 2, \"three\": 3}``::" msgstr "" -#: ../../library/stdtypes.rst:5281 +#: ../../library/stdtypes.rst:5286 msgid "" ">>> a = dict(one=1, two=2, three=3)\n" ">>> b = {'one': 1, 'two': 2, 'three': 3}\n" @@ -7620,19 +7626,19 @@ msgstr "" ">>> a == b == c == d == e == f\n" "True" -#: ../../library/stdtypes.rst:5290 +#: ../../library/stdtypes.rst:5295 msgid "" "Providing keyword arguments as in the first example only works for keys that " "are valid Python identifiers. Otherwise, any valid keys can be used." msgstr "" -#: ../../library/stdtypes.rst:5293 +#: ../../library/stdtypes.rst:5298 msgid "" "Dictionaries preserve insertion order. Note that updating a key does not " "affect the order. Keys added after deletion are inserted at the end. ::" msgstr "" -#: ../../library/stdtypes.rst:5296 +#: ../../library/stdtypes.rst:5301 msgid "" ">>> d = {\"one\": 1, \"two\": 2, \"three\": 3, \"four\": 4}\n" ">>> d\n" @@ -7664,33 +7670,33 @@ msgstr "" ">>> d\n" "{'one': 42, 'three': 3, 'four': 4, 'two': None}" -#: ../../library/stdtypes.rst:5311 +#: ../../library/stdtypes.rst:5316 msgid "" "Dictionary order is guaranteed to be insertion order. This behavior was an " "implementation detail of CPython from 3.6." msgstr "" -#: ../../library/stdtypes.rst:5315 +#: ../../library/stdtypes.rst:5320 msgid "" "These are the operations that dictionaries support (and therefore, custom " "mapping types should support too):" msgstr "" -#: ../../library/stdtypes.rst:5320 +#: ../../library/stdtypes.rst:5325 msgid "Return a list of all the keys used in the dictionary *d*." msgstr "" -#: ../../library/stdtypes.rst:5324 +#: ../../library/stdtypes.rst:5329 msgid "Return the number of items in the dictionary *d*." msgstr "" -#: ../../library/stdtypes.rst:5328 +#: ../../library/stdtypes.rst:5333 msgid "" "Return the item of *d* with key *key*. Raises a :exc:`KeyError` if *key* is " "not in the map." msgstr "" -#: ../../library/stdtypes.rst:5333 +#: ../../library/stdtypes.rst:5338 msgid "" "If a subclass of dict defines a method :meth:`~object.__missing__` and *key* " "is not present, the ``d[key]`` operation calls that method with the key " @@ -7701,7 +7707,7 @@ msgid "" "__missing__` must be a method; it cannot be an instance variable::" msgstr "" -#: ../../library/stdtypes.rst:5341 +#: ../../library/stdtypes.rst:5346 msgid "" ">>> class Counter(dict):\n" "... def __missing__(self, key):\n" @@ -7725,51 +7731,51 @@ msgstr "" ">>> c['red']\n" "1" -#: ../../library/stdtypes.rst:5352 +#: ../../library/stdtypes.rst:5357 msgid "" "The example above shows part of the implementation of :class:`collections." "Counter`. A different :meth:`!__missing__` method is used by :class:" "`collections.defaultdict`." msgstr "" -#: ../../library/stdtypes.rst:5359 +#: ../../library/stdtypes.rst:5364 msgid "Set ``d[key]`` to *value*." msgstr "將 ``d[key]`` 設為 *value*。" -#: ../../library/stdtypes.rst:5363 +#: ../../library/stdtypes.rst:5368 msgid "" "Remove ``d[key]`` from *d*. Raises a :exc:`KeyError` if *key* is not in the " "map." msgstr "從 *d* 中移除 ``d[key]``。若 *key* 不在對映中則引發 :exc:`KeyError`。" -#: ../../library/stdtypes.rst:5368 +#: ../../library/stdtypes.rst:5373 msgid "Return ``True`` if *d* has a key *key*, else ``False``." msgstr "若 *d* 有鍵 *key* 則回傳 ``True``,否則回傳 ``False``。" -#: ../../library/stdtypes.rst:5372 +#: ../../library/stdtypes.rst:5377 msgid "Equivalent to ``not key in d``." msgstr "等價於 ``not key in d``。" -#: ../../library/stdtypes.rst:5376 +#: ../../library/stdtypes.rst:5381 msgid "" "Return an iterator over the keys of the dictionary. This is a shortcut for " "``iter(d.keys())``." msgstr "" -#: ../../library/stdtypes.rst:5381 +#: ../../library/stdtypes.rst:5386 msgid "Remove all items from the dictionary." msgstr "從字典中移除所有項目。" -#: ../../library/stdtypes.rst:5385 +#: ../../library/stdtypes.rst:5390 msgid "Return a shallow copy of the dictionary." msgstr "" -#: ../../library/stdtypes.rst:5389 +#: ../../library/stdtypes.rst:5394 msgid "" "Create a new dictionary with keys from *iterable* and values set to *value*." msgstr "" -#: ../../library/stdtypes.rst:5391 +#: ../../library/stdtypes.rst:5396 msgid "" ":meth:`fromkeys` is a class method that returns a new dictionary. *value* " "defaults to ``None``. All of the values refer to just a single instance, so " @@ -7778,70 +7784,70 @@ msgid "" "` instead." msgstr "" -#: ../../library/stdtypes.rst:5399 +#: ../../library/stdtypes.rst:5404 msgid "" "Return the value for *key* if *key* is in the dictionary, else *default*. If " "*default* is not given, it defaults to ``None``, so that this method never " "raises a :exc:`KeyError`." msgstr "" -#: ../../library/stdtypes.rst:5405 +#: ../../library/stdtypes.rst:5410 msgid "" "Return a new view of the dictionary's items (``(key, value)`` pairs). See " "the :ref:`documentation of view objects `." msgstr "" -#: ../../library/stdtypes.rst:5410 +#: ../../library/stdtypes.rst:5415 msgid "" "Return a new view of the dictionary's keys. See the :ref:`documentation of " "view objects `." msgstr "" -#: ../../library/stdtypes.rst:5416 +#: ../../library/stdtypes.rst:5421 msgid "" "If *key* is in the dictionary, remove it and return its value, else return " "*default*. If *default* is not given and *key* is not in the dictionary, a :" "exc:`KeyError` is raised." msgstr "" -#: ../../library/stdtypes.rst:5422 +#: ../../library/stdtypes.rst:5427 msgid "" "Remove and return a ``(key, value)`` pair from the dictionary. Pairs are " "returned in :abbr:`LIFO (last-in, first-out)` order." msgstr "" -#: ../../library/stdtypes.rst:5425 +#: ../../library/stdtypes.rst:5430 msgid "" ":meth:`popitem` is useful to destructively iterate over a dictionary, as " "often used in set algorithms. If the dictionary is empty, calling :meth:" "`popitem` raises a :exc:`KeyError`." msgstr "" -#: ../../library/stdtypes.rst:5429 +#: ../../library/stdtypes.rst:5434 msgid "" "LIFO order is now guaranteed. In prior versions, :meth:`popitem` would " "return an arbitrary key/value pair." msgstr "" -#: ../../library/stdtypes.rst:5435 +#: ../../library/stdtypes.rst:5440 msgid "" "Return a reverse iterator over the keys of the dictionary. This is a " "shortcut for ``reversed(d.keys())``." msgstr "" -#: ../../library/stdtypes.rst:5442 +#: ../../library/stdtypes.rst:5447 msgid "" "If *key* is in the dictionary, return its value. If not, insert *key* with " "a value of *default* and return *default*. *default* defaults to ``None``." msgstr "" -#: ../../library/stdtypes.rst:5450 +#: ../../library/stdtypes.rst:5455 msgid "" "Update the dictionary with the key/value pairs from *mapping* or *iterable* " "and *kwargs*, overwriting existing keys. Return ``None``." msgstr "" -#: ../../library/stdtypes.rst:5453 +#: ../../library/stdtypes.rst:5458 msgid "" ":meth:`update` accepts either another object with a ``keys()`` method (in " "which case :meth:`~object.__getitem__` is called with every key returned " @@ -7850,20 +7856,20 @@ msgid "" "is then updated with those key/value pairs: ``d.update(red=1, blue=2)``." msgstr "" -#: ../../library/stdtypes.rst:5461 +#: ../../library/stdtypes.rst:5466 msgid "" "Return a new view of the dictionary's values. See the :ref:`documentation " "of view objects `." msgstr "" -#: ../../library/stdtypes.rst:5464 +#: ../../library/stdtypes.rst:5469 msgid "" "An equality comparison between one ``dict.values()`` view and another will " "always return ``False``. This also applies when comparing ``dict.values()`` " "to itself::" msgstr "" -#: ../../library/stdtypes.rst:5468 +#: ../../library/stdtypes.rst:5473 msgid "" ">>> d = {'a': 1}\n" ">>> d.values() == d.values()\n" @@ -7873,25 +7879,25 @@ msgstr "" ">>> d.values() == d.values()\n" "False" -#: ../../library/stdtypes.rst:5474 +#: ../../library/stdtypes.rst:5479 msgid "" "Create a new dictionary with the merged keys and values of *d* and *other*, " "which must both be dictionaries. The values of *other* take priority when " "*d* and *other* share keys." msgstr "" -#: ../../library/stdtypes.rst:5482 +#: ../../library/stdtypes.rst:5487 msgid "" "Update the dictionary *d* with keys and values from *other*, which may be " "either a :term:`mapping` or an :term:`iterable` of key/value pairs. The " "values of *other* take priority when *d* and *other* share keys." msgstr "" -#: ../../library/stdtypes.rst:5488 +#: ../../library/stdtypes.rst:5493 msgid "Dictionaries and dictionary views are reversible. ::" msgstr "" -#: ../../library/stdtypes.rst:5490 +#: ../../library/stdtypes.rst:5495 msgid "" ">>> d = {\"one\": 1, \"two\": 2, \"three\": 3, \"four\": 4}\n" ">>> d\n" @@ -7913,27 +7919,27 @@ msgstr "" ">>> list(reversed(d.items()))\n" "[('four', 4), ('three', 3), ('two', 2), ('one', 1)]" -#: ../../library/stdtypes.rst:5500 +#: ../../library/stdtypes.rst:5505 msgid "Dictionaries are now reversible." msgstr "" -#: ../../library/stdtypes.rst:5505 +#: ../../library/stdtypes.rst:5510 msgid "" ":class:`types.MappingProxyType` can be used to create a read-only view of a :" "class:`dict`." msgstr "" -#: ../../library/stdtypes.rst:5511 +#: ../../library/stdtypes.rst:5516 msgid "" "For detailed information on thread-safety guarantees for :class:`dict` " "objects, see :ref:`thread-safety-dict`." msgstr "" -#: ../../library/stdtypes.rst:5518 +#: ../../library/stdtypes.rst:5523 msgid "Dictionary view objects" msgstr "字典視圖物件" -#: ../../library/stdtypes.rst:5520 +#: ../../library/stdtypes.rst:5525 msgid "" "The objects returned by :meth:`dict.keys`, :meth:`dict.values` and :meth:" "`dict.items` are *view objects*. They provide a dynamic view on the " @@ -7941,23 +7947,23 @@ msgid "" "reflects these changes." msgstr "" -#: ../../library/stdtypes.rst:5525 +#: ../../library/stdtypes.rst:5530 msgid "" "Dictionary views can be iterated over to yield their respective data, and " "support membership tests:" msgstr "" -#: ../../library/stdtypes.rst:5530 +#: ../../library/stdtypes.rst:5535 msgid "Return the number of entries in the dictionary." msgstr "" -#: ../../library/stdtypes.rst:5534 +#: ../../library/stdtypes.rst:5539 msgid "" "Return an iterator over the keys, values or items (represented as tuples of " "``(key, value)``) in the dictionary." msgstr "" -#: ../../library/stdtypes.rst:5537 +#: ../../library/stdtypes.rst:5542 msgid "" "Keys and values are iterated over in insertion order. This allows the " "creation of ``(value, key)`` pairs using :func:`zip`: ``pairs = zip(d." @@ -7965,39 +7971,39 @@ msgid "" "[(v, k) for (k, v) in d.items()]``." msgstr "" -#: ../../library/stdtypes.rst:5542 +#: ../../library/stdtypes.rst:5547 msgid "" "Iterating views while adding or deleting entries in the dictionary may raise " "a :exc:`RuntimeError` or fail to iterate over all entries." msgstr "" -#: ../../library/stdtypes.rst:5545 +#: ../../library/stdtypes.rst:5550 msgid "Dictionary order is guaranteed to be insertion order." msgstr "" -#: ../../library/stdtypes.rst:5550 +#: ../../library/stdtypes.rst:5555 msgid "" "Return ``True`` if *x* is in the underlying dictionary's keys, values or " "items (in the latter case, *x* should be a ``(key, value)`` tuple)." msgstr "" -#: ../../library/stdtypes.rst:5555 +#: ../../library/stdtypes.rst:5560 msgid "" "Return a reverse iterator over the keys, values or items of the dictionary. " "The view will be iterated in reverse order of the insertion." msgstr "" -#: ../../library/stdtypes.rst:5558 +#: ../../library/stdtypes.rst:5563 msgid "Dictionary views are now reversible." msgstr "" -#: ../../library/stdtypes.rst:5563 +#: ../../library/stdtypes.rst:5568 msgid "" "Return a :class:`types.MappingProxyType` that wraps the original dictionary " "to which the view refers." msgstr "" -#: ../../library/stdtypes.rst:5568 +#: ../../library/stdtypes.rst:5573 msgid "" "Keys views are set-like since their entries are unique and :term:`hashable`. " "Items views also have set-like operations since the (key, value) pairs are " @@ -8011,11 +8017,11 @@ msgid "" "input." msgstr "" -#: ../../library/stdtypes.rst:5580 +#: ../../library/stdtypes.rst:5585 msgid "An example of dictionary view usage::" msgstr "" -#: ../../library/stdtypes.rst:5582 +#: ../../library/stdtypes.rst:5587 msgid "" ">>> dishes = {'eggs': 2, 'sausage': 1, 'bacon': 1, 'spam': 500}\n" ">>> keys = dishes.keys()\n" @@ -8056,11 +8062,11 @@ msgid "" "500" msgstr "" -#: ../../library/stdtypes.rst:5624 +#: ../../library/stdtypes.rst:5629 msgid "Context Manager Types" msgstr "情境管理器型別" -#: ../../library/stdtypes.rst:5631 +#: ../../library/stdtypes.rst:5636 msgid "" "Python's :keyword:`with` statement supports the concept of a runtime context " "defined by a context manager. This is implemented using a pair of methods " @@ -8071,7 +8077,7 @@ msgstr "" "要使用兩個方法來實作,該方法讓使用者定義類別能夠去定義 runtime 情境,且該情境" "在執行陳述式主體 (statement body) 之前進入、在陳述式結束時退出:" -#: ../../library/stdtypes.rst:5639 +#: ../../library/stdtypes.rst:5644 msgid "" "Enter the runtime context and return either this object or another object " "related to the runtime context. The value returned by this method is bound " @@ -8082,7 +8088,7 @@ msgstr "" "的值有被綁定到使用此情境管理器的 :keyword:`with` 陳述式的 :keyword:`!as` 子句" "中的識別字。" -#: ../../library/stdtypes.rst:5644 +#: ../../library/stdtypes.rst:5649 msgid "" "An example of a context manager that returns itself is a :term:`file " "object`. File objects return themselves from __enter__() to allow :func:" @@ -8091,7 +8097,7 @@ msgstr "" "一個會回傳自己的情境管理器範例是 :term:`file object`。檔案物件從 __enter__() " "回傳自己,以允許將 :func:`open` 用作 :keyword:`with` 陳述式中的情境運算式。" -#: ../../library/stdtypes.rst:5648 +#: ../../library/stdtypes.rst:5653 msgid "" "An example of a context manager that returns a related object is the one " "returned by :func:`decimal.localcontext`. These managers set the active " @@ -8105,7 +8111,7 @@ msgstr "" "本。這允許對 :keyword:`with` 陳述式主體中的目前十進位情境進行更改,而不會影" "響 :keyword:`!with` 陳述式外部的程式碼。" -#: ../../library/stdtypes.rst:5658 +#: ../../library/stdtypes.rst:5663 msgid "" "Exit the runtime context and return a Boolean flag indicating if any " "exception that occurred should be suppressed. If an exception occurred while " @@ -8117,7 +8123,7 @@ msgstr "" "keyword:`with` 陳述式主體時發生例外,則引數包含例外型別、值和回溯 " "(traceback) 資訊。否則,所有三個引數都是 ``None``。" -#: ../../library/stdtypes.rst:5663 +#: ../../library/stdtypes.rst:5668 msgid "" "Returning a true value from this method will cause the :keyword:`with` " "statement to suppress the exception and continue execution with the " @@ -8128,14 +8134,14 @@ msgstr "" "keyword:`!with` 陳述式之後的陳述式。否則,該例外將在該方法執行完畢後繼續傳播 " "(propagate)。" -#: ../../library/stdtypes.rst:5668 +#: ../../library/stdtypes.rst:5673 msgid "" "If this method raises an exception while handling an earlier exception from " "the :keyword:`with` block, the new exception is raised, and the original " "exception is stored in its :attr:`~BaseException.__context__` attribute." msgstr "" -#: ../../library/stdtypes.rst:5672 +#: ../../library/stdtypes.rst:5677 msgid "" "The exception passed in should never be reraised explicitly - instead, this " "method should return a false value to indicate that the method completed " @@ -8147,7 +8153,7 @@ msgstr "" "已成功完成且不希望抑制引發的例外。這讓情境管理程式碼能輕鬆檢測 :meth:" "`~object.__exit__` 方法是否曾實際失敗過。" -#: ../../library/stdtypes.rst:5678 +#: ../../library/stdtypes.rst:5683 msgid "" "Python defines several context managers to support easy thread " "synchronisation, prompt closure of files or other objects, and simpler " @@ -8159,7 +8165,7 @@ msgstr "" "及對有效十進位算術情境的更簡單操作。除了情境管理協定的實作之外,不會對特定型" "別進行特殊處理。更多範例請參閱 :mod:`contextlib` 模組。" -#: ../../library/stdtypes.rst:5684 +#: ../../library/stdtypes.rst:5689 msgid "" "Python's :term:`generator`\\s and the :class:`contextlib.contextmanager` " "decorator provide a convenient way to implement these protocols. If a " @@ -8174,7 +8180,7 @@ msgstr "" "`~contextmanager.__enter__` 和 :meth:`~contextmanager.__exit__` 方法的情境管" "理器,而不是由未裝飾產生器函式產生的疊代器。" -#: ../../library/stdtypes.rst:5691 +#: ../../library/stdtypes.rst:5696 msgid "" "Note that there is no specific slot for any of these methods in the type " "structure for Python objects in the Python/C API. Extension types wanting to " @@ -8186,7 +8192,7 @@ msgstr "" "定義這些方法的擴充型別必須將它們作為普通的 Python 可存取方法提供。與設定 " "runtime 情境的開銷相比,單一類別字典查找的開銷可以忽略不計。" -#: ../../library/stdtypes.rst:5699 +#: ../../library/stdtypes.rst:5704 msgid "" "Type Annotation Types --- :ref:`Generic Alias `, :ref:" "`Union `" @@ -8194,7 +8200,7 @@ msgstr "" "型別註釋的型別 --- :ref:`泛型別名 (Generic Alias) `、:" "ref:`聯合 (Union) `" -#: ../../library/stdtypes.rst:5704 +#: ../../library/stdtypes.rst:5709 msgid "" "The core built-in types for :term:`type annotations ` are :ref:" "`Generic Alias ` and :ref:`Union `." @@ -8202,11 +8208,11 @@ msgstr "" ":term:`型別註釋 ` 的核心內建型別是\\ :ref:`泛型別名 `\\ 和\\ :ref:`聯合 `。" -#: ../../library/stdtypes.rst:5711 +#: ../../library/stdtypes.rst:5716 msgid "Generic Alias Type" msgstr "泛型別名型別" -#: ../../library/stdtypes.rst:5717 +#: ../../library/stdtypes.rst:5722 msgid "" "``GenericAlias`` objects are generally created by :ref:`subscripting " "` a class. They are most often used with :ref:`container " @@ -8222,7 +8228,7 @@ msgstr "" "立的。``GenericAlias`` 物件主要會與\\ :term:`型別註釋 ` 一起使" "用。" -#: ../../library/stdtypes.rst:5727 +#: ../../library/stdtypes.rst:5732 msgid "" "It is generally only possible to subscript a class if the class implements " "the special method :meth:`~object.__class_getitem__`." @@ -8230,7 +8236,7 @@ msgstr "" "通常只有當類別有實作特殊方法 :meth:`~object.__class_getitem__` 時才可以去下標" "該類別。" -#: ../../library/stdtypes.rst:5730 +#: ../../library/stdtypes.rst:5735 msgid "" "A ``GenericAlias`` object acts as a proxy for a :term:`generic type`, " "implementing *parameterized generics*." @@ -8238,7 +8244,7 @@ msgstr "" "將一個 ``GenericAlias`` 物件用作 :term:`generic type` 的代理,實作\\ *參數化" "泛型 (parameterized generics)*。" -#: ../../library/stdtypes.rst:5733 +#: ../../library/stdtypes.rst:5738 msgid "" "For a container class, the argument(s) supplied to a :ref:`subscription " "` of the class may indicate the type(s) of the elements an " @@ -8250,7 +8256,7 @@ msgstr "" "物件所包含元素的型別。例如 ``set[bytes]`` 可以用於型別註釋來表示一個 :class:" "`set`,其中所有元素的型別都是 :class:`bytes`。" -#: ../../library/stdtypes.rst:5739 +#: ../../library/stdtypes.rst:5744 msgid "" "For a class which defines :meth:`~object.__class_getitem__` but is not a " "container, the argument(s) supplied to a subscription of the class will " @@ -8262,7 +8268,7 @@ msgstr "" "標引數通常會指示物件上有定義的一個或多個方法的回傳型別。例如\\ :mod:`正規表示" "式 `\\ 可以用於 :class:`str` 和 :class:`bytes` 資料型別:" -#: ../../library/stdtypes.rst:5745 +#: ../../library/stdtypes.rst:5750 msgid "" "If ``x = re.search('foo', 'foo')``, ``x`` will be a :ref:`re.Match ` object where the return values of ``x.group(0)`` and ``x[0]`` will " @@ -8274,7 +8280,7 @@ msgstr "" "別。我們就可以用 ``GenericAlias`` ``re.Match[str]`` 在型別註釋中表示這種物" "件。" -#: ../../library/stdtypes.rst:5751 +#: ../../library/stdtypes.rst:5756 msgid "" "If ``y = re.search(b'bar', b'bar')``, (note the ``b`` for :class:`bytes`), " "``y`` will also be an instance of ``re.Match``, but the return values of ``y." @@ -8287,7 +8293,7 @@ msgstr "" "別都是 :class:`bytes`。在型別註釋中,我們將用 ``re.Match[bytes]`` 來表示各" "種 :ref:`re.Match ` 物件。" -#: ../../library/stdtypes.rst:5757 +#: ../../library/stdtypes.rst:5762 msgid "" "``GenericAlias`` objects are instances of the class :class:`types." "GenericAlias`, which can also be used to create ``GenericAlias`` objects " @@ -8296,7 +8302,7 @@ msgstr "" "``GenericAlias`` 物件是 :class:`types.GenericAlias` 類別的實例,也可以用來直" "接建立 ``GenericAlias`` 物件。" -#: ../../library/stdtypes.rst:5763 +#: ../../library/stdtypes.rst:5768 msgid "" "Creates a ``GenericAlias`` representing a type ``T`` parameterized by types " "*X*, *Y*, and more depending on the ``T`` used. For example, a function " @@ -8306,7 +8312,7 @@ msgstr "" "所使用的 ``T``)來參數化。例如,一個函式需要一個包含 :class:`float` 元素的 :" "class:`list`: ::" -#: ../../library/stdtypes.rst:5768 +#: ../../library/stdtypes.rst:5773 msgid "" "def average(values: list[float]) -> float:\n" " return sum(values) / len(values)" @@ -8314,7 +8320,7 @@ msgstr "" "def average(values: list[float]) -> float:\n" " return sum(values) / len(values)" -#: ../../library/stdtypes.rst:5771 +#: ../../library/stdtypes.rst:5776 msgid "" "Another example for :term:`mapping` objects, using a :class:`dict`, which is " "a generic type expecting two type parameters representing the key type and " @@ -8325,7 +8331,7 @@ msgstr "" "別,需要兩個型別參數,分別表示鍵型別和值型別。在此範例中,函式需要一個 " "``dict``,其帶有 :class:`str` 型別的鍵和 :class:`int` 型別的值: ::" -#: ../../library/stdtypes.rst:5776 +#: ../../library/stdtypes.rst:5781 msgid "" "def send_post_request(url: str, body: dict[str, int]) -> None:\n" " ..." @@ -8333,7 +8339,7 @@ msgstr "" "def send_post_request(url: str, body: dict[str, int]) -> None:\n" " ..." -#: ../../library/stdtypes.rst:5779 +#: ../../library/stdtypes.rst:5784 msgid "" "The builtin functions :func:`isinstance` and :func:`issubclass` do not " "accept ``GenericAlias`` types for their second argument::" @@ -8341,7 +8347,7 @@ msgstr "" "內建函式 :func:`isinstance` 和 :func:`issubclass` 不接受 ``GenericAlias`` 型" "別作為第二個引數: ::" -#: ../../library/stdtypes.rst:5782 +#: ../../library/stdtypes.rst:5787 msgid "" ">>> isinstance([1, 2], list[str])\n" "Traceback (most recent call last):\n" @@ -8353,7 +8359,7 @@ msgstr "" " File \"\", line 1, in \n" "TypeError: isinstance() argument 2 cannot be a parameterized generic" -#: ../../library/stdtypes.rst:5787 +#: ../../library/stdtypes.rst:5792 msgid "" "The Python runtime does not enforce :term:`type annotations `. " "This extends to generic types and their type parameters. When creating a " @@ -8365,7 +8371,7 @@ msgstr "" "及其型別參數。當從 ``GenericAlias`` 建立容器物件時,不會檢查容器中元素的型" "別。例如,不鼓勵使用以下程式碼,但 runtime 不會出現錯誤: ::" -#: ../../library/stdtypes.rst:5793 +#: ../../library/stdtypes.rst:5798 msgid "" ">>> t = list[str]\n" ">>> t([1, 2, 3])\n" @@ -8375,13 +8381,13 @@ msgstr "" ">>> t([1, 2, 3])\n" "[1, 2, 3]" -#: ../../library/stdtypes.rst:5797 +#: ../../library/stdtypes.rst:5802 msgid "" "Furthermore, parameterized generics erase type parameters during object " "creation::" msgstr "此外,參數化泛型在物件建立期間會擦除 (erase) 型別參數: ::" -#: ../../library/stdtypes.rst:5800 +#: ../../library/stdtypes.rst:5805 msgid "" ">>> t = list[str]\n" ">>> type(t)\n" @@ -8399,13 +8405,13 @@ msgstr "" ">>> type(l)\n" "" -#: ../../library/stdtypes.rst:5808 +#: ../../library/stdtypes.rst:5813 msgid "" "Calling :func:`repr` or :func:`str` on a generic shows the parameterized " "type::" msgstr "在泛型上呼叫 :func:`repr` 或 :func:`str` 會顯示參數化型別: ::" -#: ../../library/stdtypes.rst:5810 +#: ../../library/stdtypes.rst:5815 msgid "" ">>> repr(list[int])\n" "'list[int]'\n" @@ -8419,7 +8425,7 @@ msgstr "" ">>> str(list[int])\n" "'list[int]'" -#: ../../library/stdtypes.rst:5816 +#: ../../library/stdtypes.rst:5821 msgid "" "The :meth:`~object.__getitem__` method of generic containers will raise an " "exception to disallow mistakes like ``dict[str][str]``::" @@ -8427,7 +8433,7 @@ msgstr "" "為防止像是 ``dict[str][str]`` 的錯誤出現,泛型容器的 :meth:`~object." "__getitem__` 方法會在這種情況下引發例外: ::" -#: ../../library/stdtypes.rst:5819 +#: ../../library/stdtypes.rst:5824 msgid "" ">>> dict[str][str]\n" "Traceback (most recent call last):\n" @@ -8439,7 +8445,7 @@ msgstr "" " ...\n" "TypeError: dict[str] is not a generic class" -#: ../../library/stdtypes.rst:5824 +#: ../../library/stdtypes.rst:5829 msgid "" "However, such expressions are valid when :ref:`type variables ` " "are used. The index must have as many elements as there are type variable " @@ -8449,7 +8455,7 @@ msgstr "" "的。索引的元素數量必須與 ``GenericAlias`` 物件的 :attr:`~genericalias." "__args__` 中的型別變數項目一樣多: ::" -#: ../../library/stdtypes.rst:5828 +#: ../../library/stdtypes.rst:5833 msgid "" ">>> from typing import TypeVar\n" ">>> Y = TypeVar('Y')\n" @@ -8461,253 +8467,253 @@ msgstr "" ">>> dict[str, Y][int]\n" "dict[str, int]" -#: ../../library/stdtypes.rst:5835 +#: ../../library/stdtypes.rst:5840 msgid "Standard Generic Classes" msgstr "標準泛型類別" -#: ../../library/stdtypes.rst:5837 +#: ../../library/stdtypes.rst:5842 msgid "" "The following standard library classes support parameterized generics. This " "list is non-exhaustive." msgstr "以下標準函式庫類別有支援參數化泛型。此列表並非詳盡無遺。" -#: ../../library/stdtypes.rst:5840 +#: ../../library/stdtypes.rst:5845 msgid ":class:`tuple`" msgstr ":class:`tuple`" -#: ../../library/stdtypes.rst:5841 +#: ../../library/stdtypes.rst:5846 msgid ":class:`list`" msgstr ":class:`list`" -#: ../../library/stdtypes.rst:5842 +#: ../../library/stdtypes.rst:5847 msgid ":class:`dict`" msgstr ":class:`dict`" -#: ../../library/stdtypes.rst:5843 +#: ../../library/stdtypes.rst:5848 msgid ":class:`set`" msgstr ":class:`set`" -#: ../../library/stdtypes.rst:5844 +#: ../../library/stdtypes.rst:5849 msgid ":class:`frozenset`" msgstr ":class:`frozenset`" -#: ../../library/stdtypes.rst:5845 +#: ../../library/stdtypes.rst:5850 msgid ":class:`type`" msgstr ":class:`type`" -#: ../../library/stdtypes.rst:5846 +#: ../../library/stdtypes.rst:5851 msgid ":class:`asyncio.Future`" msgstr ":class:`asyncio.Future`" -#: ../../library/stdtypes.rst:5847 +#: ../../library/stdtypes.rst:5852 msgid ":class:`asyncio.Task`" msgstr ":class:`asyncio.Task`" -#: ../../library/stdtypes.rst:5848 +#: ../../library/stdtypes.rst:5853 msgid ":class:`collections.deque`" msgstr ":class:`collections.deque`" -#: ../../library/stdtypes.rst:5849 +#: ../../library/stdtypes.rst:5854 msgid ":class:`collections.defaultdict`" msgstr ":class:`collections.defaultdict`" -#: ../../library/stdtypes.rst:5850 +#: ../../library/stdtypes.rst:5855 msgid ":class:`collections.OrderedDict`" msgstr ":class:`collections.OrderedDict`" -#: ../../library/stdtypes.rst:5851 +#: ../../library/stdtypes.rst:5856 msgid ":class:`collections.Counter`" msgstr ":class:`collections.Counter`" -#: ../../library/stdtypes.rst:5852 +#: ../../library/stdtypes.rst:5857 msgid ":class:`collections.ChainMap`" msgstr ":class:`collections.ChainMap`" -#: ../../library/stdtypes.rst:5853 +#: ../../library/stdtypes.rst:5858 msgid ":class:`collections.abc.Awaitable`" msgstr ":class:`collections.abc.Awaitable`" -#: ../../library/stdtypes.rst:5854 +#: ../../library/stdtypes.rst:5859 msgid ":class:`collections.abc.Coroutine`" msgstr ":class:`collections.abc.Coroutine`" -#: ../../library/stdtypes.rst:5855 +#: ../../library/stdtypes.rst:5860 msgid ":class:`collections.abc.AsyncIterable`" msgstr ":class:`collections.abc.AsyncIterable`" -#: ../../library/stdtypes.rst:5856 +#: ../../library/stdtypes.rst:5861 msgid ":class:`collections.abc.AsyncIterator`" msgstr ":class:`collections.abc.AsyncIterator`" -#: ../../library/stdtypes.rst:5857 +#: ../../library/stdtypes.rst:5862 msgid ":class:`collections.abc.AsyncGenerator`" msgstr ":class:`collections.abc.AsyncGenerator`" -#: ../../library/stdtypes.rst:5858 +#: ../../library/stdtypes.rst:5863 msgid ":class:`collections.abc.Iterable`" msgstr ":class:`collections.abc.Iterable`" -#: ../../library/stdtypes.rst:5859 +#: ../../library/stdtypes.rst:5864 msgid ":class:`collections.abc.Iterator`" msgstr ":class:`collections.abc.Iterator`" -#: ../../library/stdtypes.rst:5860 +#: ../../library/stdtypes.rst:5865 msgid ":class:`collections.abc.Generator`" msgstr ":class:`collections.abc.Generator`" -#: ../../library/stdtypes.rst:5861 +#: ../../library/stdtypes.rst:5866 msgid ":class:`collections.abc.Reversible`" msgstr ":class:`collections.abc.Reversible`" -#: ../../library/stdtypes.rst:5862 +#: ../../library/stdtypes.rst:5867 msgid ":class:`collections.abc.Container`" msgstr ":class:`collections.abc.Container`" -#: ../../library/stdtypes.rst:5863 +#: ../../library/stdtypes.rst:5868 msgid ":class:`collections.abc.Collection`" msgstr ":class:`collections.abc.Collection`" -#: ../../library/stdtypes.rst:5864 +#: ../../library/stdtypes.rst:5869 msgid ":class:`collections.abc.Callable`" msgstr ":class:`collections.abc.Callable`" -#: ../../library/stdtypes.rst:5865 +#: ../../library/stdtypes.rst:5870 msgid ":class:`collections.abc.Set`" msgstr ":class:`collections.abc.Set`" -#: ../../library/stdtypes.rst:5866 +#: ../../library/stdtypes.rst:5871 msgid ":class:`collections.abc.MutableSet`" msgstr ":class:`collections.abc.MutableSet`" -#: ../../library/stdtypes.rst:5867 +#: ../../library/stdtypes.rst:5872 msgid ":class:`collections.abc.Mapping`" msgstr ":class:`collections.abc.Mapping`" -#: ../../library/stdtypes.rst:5868 +#: ../../library/stdtypes.rst:5873 msgid ":class:`collections.abc.MutableMapping`" msgstr ":class:`collections.abc.MutableMapping`" -#: ../../library/stdtypes.rst:5869 +#: ../../library/stdtypes.rst:5874 msgid ":class:`collections.abc.Sequence`" msgstr ":class:`collections.abc.Sequence`" -#: ../../library/stdtypes.rst:5870 +#: ../../library/stdtypes.rst:5875 msgid ":class:`collections.abc.MutableSequence`" msgstr ":class:`collections.abc.MutableSequence`" -#: ../../library/stdtypes.rst:5871 +#: ../../library/stdtypes.rst:5876 msgid ":class:`collections.abc.ByteString`" msgstr ":class:`collections.abc.ByteString`" -#: ../../library/stdtypes.rst:5872 +#: ../../library/stdtypes.rst:5877 msgid ":class:`collections.abc.MappingView`" msgstr ":class:`collections.abc.MappingView`" -#: ../../library/stdtypes.rst:5873 +#: ../../library/stdtypes.rst:5878 msgid ":class:`collections.abc.KeysView`" msgstr ":class:`collections.abc.KeysView`" -#: ../../library/stdtypes.rst:5874 +#: ../../library/stdtypes.rst:5879 msgid ":class:`collections.abc.ItemsView`" msgstr ":class:`collections.abc.ItemsView`" -#: ../../library/stdtypes.rst:5875 +#: ../../library/stdtypes.rst:5880 msgid ":class:`collections.abc.ValuesView`" msgstr ":class:`collections.abc.ValuesView`" -#: ../../library/stdtypes.rst:5876 +#: ../../library/stdtypes.rst:5881 msgid ":class:`contextlib.AbstractContextManager`" msgstr ":class:`contextlib.AbstractContextManager`" -#: ../../library/stdtypes.rst:5877 +#: ../../library/stdtypes.rst:5882 msgid ":class:`contextlib.AbstractAsyncContextManager`" msgstr ":class:`contextlib.AbstractAsyncContextManager`" -#: ../../library/stdtypes.rst:5878 +#: ../../library/stdtypes.rst:5883 msgid ":class:`dataclasses.Field`" msgstr ":class:`dataclasses.Field`" -#: ../../library/stdtypes.rst:5879 +#: ../../library/stdtypes.rst:5884 msgid ":class:`functools.cached_property`" msgstr ":class:`functools.cached_property`" -#: ../../library/stdtypes.rst:5880 +#: ../../library/stdtypes.rst:5885 msgid ":class:`functools.partialmethod`" msgstr ":class:`functools.partialmethod`" -#: ../../library/stdtypes.rst:5881 +#: ../../library/stdtypes.rst:5886 msgid ":class:`os.PathLike`" msgstr ":class:`os.PathLike`" -#: ../../library/stdtypes.rst:5882 +#: ../../library/stdtypes.rst:5887 msgid ":class:`queue.LifoQueue`" msgstr ":class:`queue.LifoQueue`" -#: ../../library/stdtypes.rst:5883 +#: ../../library/stdtypes.rst:5888 msgid ":class:`queue.Queue`" msgstr ":class:`queue.Queue`" -#: ../../library/stdtypes.rst:5884 +#: ../../library/stdtypes.rst:5889 msgid ":class:`queue.PriorityQueue`" msgstr ":class:`queue.PriorityQueue`" -#: ../../library/stdtypes.rst:5885 +#: ../../library/stdtypes.rst:5890 msgid ":class:`queue.SimpleQueue`" msgstr ":class:`queue.SimpleQueue`" -#: ../../library/stdtypes.rst:5886 +#: ../../library/stdtypes.rst:5891 msgid ":ref:`re.Pattern `" msgstr ":ref:`re.Pattern `" -#: ../../library/stdtypes.rst:5887 +#: ../../library/stdtypes.rst:5892 msgid ":ref:`re.Match `" msgstr ":ref:`re.Match `" -#: ../../library/stdtypes.rst:5888 +#: ../../library/stdtypes.rst:5893 msgid ":class:`shelve.BsdDbShelf`" msgstr ":class:`shelve.BsdDbShelf`" -#: ../../library/stdtypes.rst:5889 +#: ../../library/stdtypes.rst:5894 msgid ":class:`shelve.DbfilenameShelf`" msgstr ":class:`shelve.DbfilenameShelf`" -#: ../../library/stdtypes.rst:5890 +#: ../../library/stdtypes.rst:5895 msgid ":class:`shelve.Shelf`" msgstr ":class:`shelve.Shelf`" -#: ../../library/stdtypes.rst:5891 +#: ../../library/stdtypes.rst:5896 msgid ":class:`types.MappingProxyType`" msgstr ":class:`types.MappingProxyType`" -#: ../../library/stdtypes.rst:5892 +#: ../../library/stdtypes.rst:5897 msgid ":class:`weakref.WeakKeyDictionary`" msgstr ":class:`weakref.WeakKeyDictionary`" -#: ../../library/stdtypes.rst:5893 +#: ../../library/stdtypes.rst:5898 msgid ":class:`weakref.WeakMethod`" msgstr ":class:`weakref.WeakMethod`" -#: ../../library/stdtypes.rst:5894 +#: ../../library/stdtypes.rst:5899 msgid ":class:`weakref.WeakSet`" msgstr ":class:`weakref.WeakSet`" -#: ../../library/stdtypes.rst:5895 +#: ../../library/stdtypes.rst:5900 msgid ":class:`weakref.WeakValueDictionary`" msgstr ":class:`weakref.WeakValueDictionary`" -#: ../../library/stdtypes.rst:5900 +#: ../../library/stdtypes.rst:5905 msgid "Special Attributes of ``GenericAlias`` objects" msgstr "``GenericAlias`` 物件的特殊屬性" -#: ../../library/stdtypes.rst:5902 +#: ../../library/stdtypes.rst:5907 msgid "All parameterized generics implement special read-only attributes." msgstr "所有參數化泛型都有實作特殊的唯讀屬性。" -#: ../../library/stdtypes.rst:5906 +#: ../../library/stdtypes.rst:5911 msgid "This attribute points at the non-parameterized generic class::" msgstr "此屬性指向非參數化泛型類別: ::" -#: ../../library/stdtypes.rst:5908 +#: ../../library/stdtypes.rst:5913 msgid "" ">>> list[int].__origin__\n" "" @@ -8715,7 +8721,7 @@ msgstr "" ">>> list[int].__origin__\n" "" -#: ../../library/stdtypes.rst:5914 +#: ../../library/stdtypes.rst:5919 msgid "" "This attribute is a :class:`tuple` (possibly of length 1) of generic types " "passed to the original :meth:`~object.__class_getitem__` of the generic " @@ -8724,7 +8730,7 @@ msgstr "" "此屬性是傳遞給泛型類別之原始 :meth:`~object.__class_getitem__` 的泛型型別 :" "class:`tuple`\\ (長度可以為 1): ::" -#: ../../library/stdtypes.rst:5918 +#: ../../library/stdtypes.rst:5923 msgid "" ">>> dict[str, list[int]].__args__\n" "(, list[int])" @@ -8732,7 +8738,7 @@ msgstr "" ">>> dict[str, list[int]].__args__\n" "(, list[int])" -#: ../../library/stdtypes.rst:5924 +#: ../../library/stdtypes.rst:5929 msgid "" "This attribute is a lazily computed tuple (possibly empty) of unique type " "variables found in ``__args__``::" @@ -8740,7 +8746,7 @@ msgstr "" "此屬性是個會被延遲計算 (lazily computed) 的元組(可能為空),包含了在 " "``__args__`` 中找得到的不重複型別變數: ::" -#: ../../library/stdtypes.rst:5927 +#: ../../library/stdtypes.rst:5932 msgid "" ">>> from typing import TypeVar\n" "\n" @@ -8754,7 +8760,7 @@ msgstr "" ">>> list[T].__parameters__\n" "(~T,)" -#: ../../library/stdtypes.rst:5935 +#: ../../library/stdtypes.rst:5940 msgid "" "A ``GenericAlias`` object with :class:`typing.ParamSpec` parameters may not " "have correct ``__parameters__`` after substitution because :class:`typing." @@ -8764,7 +8770,7 @@ msgstr "" "有正確的 ``__parameters__``,因為 :class:`typing.ParamSpec` 主要用於靜態型別" "檢查。" -#: ../../library/stdtypes.rst:5942 +#: ../../library/stdtypes.rst:5947 msgid "" "A boolean that is true if the alias has been unpacked using the ``*`` " "operator (see :data:`~typing.TypeVarTuple`)." @@ -8772,19 +8778,19 @@ msgstr "" "如果別名已使用 ``*`` 運算子解包 (unpack) 則為 true 的布林值(請參閱 :data:" "`~typing.TypeVarTuple`\\ )。" -#: ../../library/stdtypes.rst:5950 +#: ../../library/stdtypes.rst:5955 msgid ":pep:`484` - Type Hints" msgstr ":pep:`484` - 型別提示" -#: ../../library/stdtypes.rst:5951 +#: ../../library/stdtypes.rst:5956 msgid "Introducing Python's framework for type annotations." msgstr "引入 Python 的型別註釋框架。" -#: ../../library/stdtypes.rst:5953 +#: ../../library/stdtypes.rst:5958 msgid ":pep:`585` - Type Hinting Generics In Standard Collections" msgstr ":pep:`585` - 標準集合 (Standard Collections) 中的型別提示泛型" -#: ../../library/stdtypes.rst:5954 +#: ../../library/stdtypes.rst:5959 msgid "" "Introducing the ability to natively parameterize standard-library classes, " "provided they implement the special class method :meth:`~object." @@ -8793,7 +8799,7 @@ msgstr "" "引入原生參數化標準函式庫類別的能力,前提是它們有實作特殊的類別方法 :meth:" "`~object.__class_getitem__`。" -#: ../../library/stdtypes.rst:5958 +#: ../../library/stdtypes.rst:5963 msgid "" ":ref:`Generics`, :ref:`user-defined generics ` and :" "class:`typing.Generic`" @@ -8801,18 +8807,18 @@ msgstr "" ":ref:`Generics`、:ref:`使用者定義泛型 `\\ 和 :class:" "`typing.Generic`" -#: ../../library/stdtypes.rst:5959 +#: ../../library/stdtypes.rst:5964 msgid "" "Documentation on how to implement generic classes that can be parameterized " "at runtime and understood by static type-checkers." msgstr "" "有關如何實作可以在 runtime 參數化並能被靜態型別檢查器理解的泛型類別的文件。" -#: ../../library/stdtypes.rst:5968 +#: ../../library/stdtypes.rst:5973 msgid "Union Type" msgstr "聯合型別 (Union Type)" -#: ../../library/stdtypes.rst:5974 +#: ../../library/stdtypes.rst:5979 msgid "" "A union object holds the value of the ``|`` (bitwise or) operation on " "multiple :ref:`type objects `. These types are intended " @@ -8825,7 +8831,7 @@ msgstr "" "釋 (type annotation) `。與下標 :data:`typing.Union` 相比,聯合型" "別運算式可以讓型別提示語法更清晰簡潔。" -#: ../../library/stdtypes.rst:5981 +#: ../../library/stdtypes.rst:5986 msgid "" "Defines a union object which holds types *X*, *Y*, and so forth. ``X | Y`` " "means either X or Y. It is equivalent to ``typing.Union[X, Y]``. For " @@ -8836,7 +8842,7 @@ msgstr "" "``typing.Union[X, Y]``。舉例來說,下列函式需要一個型別為 :class:`int` 或 :" "class:`float` 的引數: ::" -#: ../../library/stdtypes.rst:5986 +#: ../../library/stdtypes.rst:5991 msgid "" "def square(number: int | float) -> int | float:\n" " return number ** 2" @@ -8844,7 +8850,7 @@ msgstr "" "def square(number: int | float) -> int | float:\n" " return number ** 2" -#: ../../library/stdtypes.rst:5991 +#: ../../library/stdtypes.rst:5996 msgid "" "The ``|`` operand cannot be used at runtime to define unions where one or " "more members is a forward reference. For example, ``int | \"Foo\"``, where " @@ -8857,40 +8863,40 @@ msgstr "" "義類別的參照,將在 runtime 失敗。對於包含向前參照的聯合,請將整個運算式以字串" "呈現,例如 ``\"int | Foo\"``。" -#: ../../library/stdtypes.rst:5999 +#: ../../library/stdtypes.rst:6004 msgid "" "Union objects can be tested for equality with other union objects. Details:" msgstr "聯合物件可以與其他聯合物件一起進行相等性測試。細節如下:" -#: ../../library/stdtypes.rst:6001 +#: ../../library/stdtypes.rst:6006 msgid "Unions of unions are flattened::" msgstr "聯合的聯合會被扁平化: ::" -#: ../../library/stdtypes.rst:6003 +#: ../../library/stdtypes.rst:6008 msgid "(int | str) | float == int | str | float" msgstr "(int | str) | float == int | str | float" -#: ../../library/stdtypes.rst:6005 +#: ../../library/stdtypes.rst:6010 msgid "Redundant types are removed::" msgstr "冗餘型別會被刪除: ::" -#: ../../library/stdtypes.rst:6007 +#: ../../library/stdtypes.rst:6012 msgid "int | str | int == int | str" msgstr "int | str | int == int | str" -#: ../../library/stdtypes.rst:6009 +#: ../../library/stdtypes.rst:6014 msgid "When comparing unions, the order is ignored::" msgstr "比較聯合時,順序會被忽略: ::" -#: ../../library/stdtypes.rst:6011 +#: ../../library/stdtypes.rst:6016 msgid "int | str == str | int" msgstr "int | str == str | int" -#: ../../library/stdtypes.rst:6013 +#: ../../library/stdtypes.rst:6018 msgid "It creates instances of :class:`typing.Union`::" msgstr "它會建立 :class:`typing.Union` 的實例: ::" -#: ../../library/stdtypes.rst:6015 +#: ../../library/stdtypes.rst:6020 msgid "" "int | str == typing.Union[int, str]\n" "type(int | str) is typing.Union" @@ -8898,21 +8904,21 @@ msgstr "" "int | str == typing.Union[int, str]\n" "type(int | str) is typing.Union" -#: ../../library/stdtypes.rst:6018 +#: ../../library/stdtypes.rst:6023 msgid "Optional types can be spelled as a union with ``None``::" msgstr "可選型別可以表示為與 ``None`` 的聯合: ::" -#: ../../library/stdtypes.rst:6020 +#: ../../library/stdtypes.rst:6025 msgid "str | None == typing.Optional[str]" msgstr "str | None == typing.Optional[str]" -#: ../../library/stdtypes.rst:6025 +#: ../../library/stdtypes.rst:6030 msgid "" "Calls to :func:`isinstance` and :func:`issubclass` are also supported with a " "union object::" msgstr "聯合物件也支援 :func:`isinstance` 和 :func:`issubclass` 的呼叫: ::" -#: ../../library/stdtypes.rst:6028 +#: ../../library/stdtypes.rst:6033 msgid "" ">>> isinstance(\"\", int | str)\n" "True" @@ -8920,14 +8926,14 @@ msgstr "" ">>> isinstance(\"\", int | str)\n" "True" -#: ../../library/stdtypes.rst:6031 +#: ../../library/stdtypes.rst:6036 msgid "" "However, :ref:`parameterized generics ` in union objects " "cannot be checked::" msgstr "" "然而聯合物件中的\\ :ref:`參數化泛型 `\\ 則無法被檢查: ::" -#: ../../library/stdtypes.rst:6034 +#: ../../library/stdtypes.rst:6039 msgid "" ">>> isinstance(1, int | list[int]) # short-circuit evaluation\n" "True\n" @@ -8937,7 +8943,7 @@ msgid "" "TypeError: isinstance() argument 2 cannot be a parameterized generic" msgstr "" -#: ../../library/stdtypes.rst:6041 +#: ../../library/stdtypes.rst:6046 msgid "" "The user-exposed type for the union object can be accessed from :class:" "`typing.Union` and used for :func:`isinstance` checks::" @@ -8945,7 +8951,7 @@ msgstr "" "構成聯合物件的對使用者公開型別 (user-exposed type) 可以透過 :data:`typing." "Union` 存取並用於 :func:`isinstance` 檢查: ::" -#: ../../library/stdtypes.rst:6044 +#: ../../library/stdtypes.rst:6049 msgid "" ">>> import typing\n" ">>> isinstance(int | str, typing.Union)\n" @@ -8963,7 +8969,7 @@ msgstr "" " File \"\", line 1, in \n" "TypeError: cannot create 'typing.Union' instances" -#: ../../library/stdtypes.rst:6053 +#: ../../library/stdtypes.rst:6058 msgid "" "The :meth:`!__or__` method for type objects was added to support the syntax " "``X | Y``. If a metaclass implements :meth:`!__or__`, the Union may " @@ -8972,7 +8978,7 @@ msgstr "" "新增了型別物件的 :meth:`!__or__` 方法來支援 ``X | Y`` 語法。如果元類別有實" "作 :meth:`!__or__`,則 Union 可以覆寫 (override) 它: ::" -#: ../../library/stdtypes.rst:6057 +#: ../../library/stdtypes.rst:6062 msgid "" ">>> class M(type):\n" "... def __or__(self, other):\n" @@ -8998,32 +9004,32 @@ msgstr "" ">>> int | C\n" "int | C" -#: ../../library/stdtypes.rst:6073 +#: ../../library/stdtypes.rst:6078 msgid ":pep:`604` -- PEP proposing the ``X | Y`` syntax and the Union type." msgstr ":pep:`604` -- PEP 提出 ``X | Y`` 語法和聯合型別。" -#: ../../library/stdtypes.rst:6079 +#: ../../library/stdtypes.rst:6084 msgid "" "Union objects are now instances of :class:`typing.Union`. Previously, they " "were instances of :class:`types.UnionType`, which remains an alias for :" "class:`typing.Union`." msgstr "" -#: ../../library/stdtypes.rst:6086 +#: ../../library/stdtypes.rst:6091 msgid "Other Built-in Types" msgstr "其他內建型別" -#: ../../library/stdtypes.rst:6088 +#: ../../library/stdtypes.rst:6093 msgid "" "The interpreter supports several other kinds of objects. Most of these " "support only one or two operations." msgstr "" -#: ../../library/stdtypes.rst:6095 +#: ../../library/stdtypes.rst:6100 msgid "Modules" msgstr "模組" -#: ../../library/stdtypes.rst:6097 +#: ../../library/stdtypes.rst:6102 msgid "" "The only special operation on a module is attribute access: ``m.name``, " "where *m* is a module and *name* accesses a name defined in *m*'s symbol " @@ -9034,7 +9040,7 @@ msgid "" "*foo* somewhere.)" msgstr "" -#: ../../library/stdtypes.rst:6104 +#: ../../library/stdtypes.rst:6109 msgid "" "A special attribute of every module is :attr:`~object.__dict__`. This is the " "dictionary containing the module's symbol table. Modifying this dictionary " @@ -9045,32 +9051,32 @@ msgid "" "recommended." msgstr "" -#: ../../library/stdtypes.rst:6112 +#: ../../library/stdtypes.rst:6117 msgid "" "Modules built into the interpreter are written like this: ````. If loaded from a file, they are written as ````." msgstr "" -#: ../../library/stdtypes.rst:6120 +#: ../../library/stdtypes.rst:6125 msgid "Classes and Class Instances" msgstr "類別與類別實例" -#: ../../library/stdtypes.rst:6122 +#: ../../library/stdtypes.rst:6127 msgid "See :ref:`objects` and :ref:`class` for these." msgstr "請見 :ref:`objects` 和 :ref:`class`。" -#: ../../library/stdtypes.rst:6128 +#: ../../library/stdtypes.rst:6133 msgid "Functions" msgstr "函式" -#: ../../library/stdtypes.rst:6130 +#: ../../library/stdtypes.rst:6135 msgid "" "Function objects are created by function definitions. The only operation on " "a function object is to call it: ``func(argument-list)``." msgstr "" -#: ../../library/stdtypes.rst:6133 +#: ../../library/stdtypes.rst:6138 msgid "" "There are really two flavors of function objects: built-in functions and " "user-defined functions. Both support the same operation (to call the " @@ -9078,15 +9084,15 @@ msgid "" "types." msgstr "" -#: ../../library/stdtypes.rst:6137 +#: ../../library/stdtypes.rst:6142 msgid "See :ref:`function` for more information." msgstr "更多資訊請見 :ref:`function`。" -#: ../../library/stdtypes.rst:6143 +#: ../../library/stdtypes.rst:6148 msgid "Methods" msgstr "方法" -#: ../../library/stdtypes.rst:6147 +#: ../../library/stdtypes.rst:6152 msgid "" "Methods are functions that are called using the attribute notation. There " "are two flavors: :ref:`built-in methods ` (such as :meth:" @@ -9094,7 +9100,7 @@ msgid "" "methods>`. Built-in methods are described with the types that support them." msgstr "" -#: ../../library/stdtypes.rst:6153 +#: ../../library/stdtypes.rst:6158 msgid "" "If you access a method (a function defined in a class namespace) through an " "instance, you get a special object: a :dfn:`bound method` (also called :ref:" @@ -9107,7 +9113,7 @@ msgid "" "arg-2, ..., arg-n)``." msgstr "" -#: ../../library/stdtypes.rst:6164 +#: ../../library/stdtypes.rst:6169 msgid "" "Like :ref:`function objects `, bound method objects " "support getting arbitrary attributes. However, since method attributes are " @@ -9118,7 +9124,7 @@ msgid "" "underlying function object:" msgstr "" -#: ../../library/stdtypes.rst:6172 +#: ../../library/stdtypes.rst:6177 msgid "" ">>> class C:\n" "... def method(self):\n" @@ -9146,15 +9152,15 @@ msgstr "" ">>> c.method.whoami\n" "'my name is method'" -#: ../../library/stdtypes.rst:6187 +#: ../../library/stdtypes.rst:6192 msgid "See :ref:`instance-methods` for more information." msgstr "更多資訊請見 :ref:`instance-methods`。" -#: ../../library/stdtypes.rst:6195 +#: ../../library/stdtypes.rst:6200 msgid "Code Objects" msgstr "程式碼物件" -#: ../../library/stdtypes.rst:6201 +#: ../../library/stdtypes.rst:6206 msgid "" "Code objects are used by the implementation to represent \"pseudo-compiled\" " "executable Python code such as a function body. They differ from function " @@ -9164,7 +9170,7 @@ msgid "" "`~function.__code__` attribute. See also the :mod:`code` module." msgstr "" -#: ../../library/stdtypes.rst:6208 +#: ../../library/stdtypes.rst:6213 msgid "" "Accessing :attr:`~function.__code__` raises an :ref:`auditing event " "` ``object.__getattr__`` with arguments ``obj`` and " @@ -9173,21 +9179,21 @@ msgstr "" "存取 :attr:`~function.__code__` 會引發一個附帶引數 ``obj`` 與 " "``\"__code__\"`` 的\\ :ref:`稽核事件 ` ``object.__getattr__``。" -#: ../../library/stdtypes.rst:6215 +#: ../../library/stdtypes.rst:6220 msgid "" "A code object can be executed or evaluated by passing it (instead of a " "source string) to the :func:`exec` or :func:`eval` built-in functions." msgstr "" -#: ../../library/stdtypes.rst:6218 +#: ../../library/stdtypes.rst:6223 msgid "See :ref:`types` for more information." msgstr "更多資訊請見 :ref:`types`。" -#: ../../library/stdtypes.rst:6224 +#: ../../library/stdtypes.rst:6229 msgid "Type Objects" msgstr "" -#: ../../library/stdtypes.rst:6230 +#: ../../library/stdtypes.rst:6235 msgid "" "Type objects represent the various object types. An object's type is " "accessed by the built-in function :func:`type`. There are no special " @@ -9195,30 +9201,30 @@ msgid "" "standard built-in types." msgstr "" -#: ../../library/stdtypes.rst:6235 +#: ../../library/stdtypes.rst:6240 msgid "Types are written like this: ````." msgstr "" -#: ../../library/stdtypes.rst:6241 +#: ../../library/stdtypes.rst:6246 msgid "The Null Object" msgstr "Null 物件" -#: ../../library/stdtypes.rst:6243 +#: ../../library/stdtypes.rst:6248 msgid "" "This object is returned by functions that don't explicitly return a value. " "It supports no special operations. There is exactly one null object, named " "``None`` (a built-in name). ``type(None)()`` produces the same singleton." msgstr "" -#: ../../library/stdtypes.rst:6247 +#: ../../library/stdtypes.rst:6252 msgid "It is written as ``None``." msgstr "它被寫為 ``None``。" -#: ../../library/stdtypes.rst:6254 +#: ../../library/stdtypes.rst:6259 msgid "The Ellipsis Object" msgstr "Ellipsis 物件" -#: ../../library/stdtypes.rst:6256 +#: ../../library/stdtypes.rst:6261 msgid "" "This object is commonly used to indicate that something is omitted. It " "supports no special operations. There is exactly one ellipsis object, " @@ -9226,63 +9232,63 @@ msgid "" "the :const:`Ellipsis` singleton." msgstr "" -#: ../../library/stdtypes.rst:6261 +#: ../../library/stdtypes.rst:6266 msgid "It is written as ``Ellipsis`` or ``...``." msgstr "它被寫為 ``Ellipsis`` 或 ``...``。" -#: ../../library/stdtypes.rst:6263 +#: ../../library/stdtypes.rst:6268 msgid "" "In typical use, ``...`` as the ``Ellipsis`` object appears in a few " "different places, for instance:" msgstr "" -#: ../../library/stdtypes.rst:6266 +#: ../../library/stdtypes.rst:6271 msgid "" "In type annotations, such as :ref:`callable arguments ` or :ref:`tuple elements `." msgstr "" -#: ../../library/stdtypes.rst:6269 +#: ../../library/stdtypes.rst:6274 msgid "" "As the body of a function instead of a :ref:`pass statement `." msgstr "" -#: ../../library/stdtypes.rst:6271 +#: ../../library/stdtypes.rst:6276 msgid "" "In third-party libraries, such as `Numpy's slicing and striding `_." msgstr "" -#: ../../library/stdtypes.rst:6274 +#: ../../library/stdtypes.rst:6279 msgid "" "Python also uses three dots in ways that are not ``Ellipsis`` objects, for " "instance:" msgstr "" -#: ../../library/stdtypes.rst:6276 +#: ../../library/stdtypes.rst:6281 msgid "" "Doctest's :const:`ELLIPSIS `, as a pattern for missing " "content." msgstr "" -#: ../../library/stdtypes.rst:6278 +#: ../../library/stdtypes.rst:6283 msgid "" "The default Python prompt of the :term:`interactive` shell when partial " "input is incomplete." msgstr "" -#: ../../library/stdtypes.rst:6280 +#: ../../library/stdtypes.rst:6285 msgid "" "Lastly, the Python documentation often uses three dots in conventional " "English usage to mean omitted content, even in code examples that also use " "them as the ``Ellipsis``." msgstr "" -#: ../../library/stdtypes.rst:6288 +#: ../../library/stdtypes.rst:6293 msgid "The NotImplemented Object" msgstr "NotImplemented 物件" -#: ../../library/stdtypes.rst:6290 +#: ../../library/stdtypes.rst:6295 msgid "" "This object is returned from comparisons and binary operations when they are " "asked to operate on types they don't support. See :ref:`comparisons` for " @@ -9290,64 +9296,64 @@ msgid "" "`type(NotImplemented)()` produces the singleton instance." msgstr "" -#: ../../library/stdtypes.rst:6295 +#: ../../library/stdtypes.rst:6300 msgid "It is written as :code:`NotImplemented`." msgstr "它被寫為 :code:`NotImplemented`。" -#: ../../library/stdtypes.rst:6301 +#: ../../library/stdtypes.rst:6306 msgid "Internal Objects" msgstr "內部物件" -#: ../../library/stdtypes.rst:6303 +#: ../../library/stdtypes.rst:6308 msgid "" "See :ref:`types` for this information. It describes :ref:`stack frame " "objects `, :ref:`traceback objects `, and " "slice objects." msgstr "" -#: ../../library/stdtypes.rst:6311 +#: ../../library/stdtypes.rst:6316 msgid "Special Attributes" msgstr "特殊屬性" -#: ../../library/stdtypes.rst:6313 +#: ../../library/stdtypes.rst:6318 msgid "" "The implementation adds a few special read-only attributes to several object " "types, where they are relevant. Some of these are not reported by the :func:" "`dir` built-in function." msgstr "" -#: ../../library/stdtypes.rst:6320 +#: ../../library/stdtypes.rst:6325 msgid "" "The name of the class, function, method, descriptor, or generator instance." msgstr "" -#: ../../library/stdtypes.rst:6326 +#: ../../library/stdtypes.rst:6331 msgid "" "The :term:`qualified name` of the class, function, method, descriptor, or " "generator instance." msgstr "" -#: ../../library/stdtypes.rst:6334 +#: ../../library/stdtypes.rst:6339 msgid "The name of the module in which a class or function was defined." msgstr "" -#: ../../library/stdtypes.rst:6339 +#: ../../library/stdtypes.rst:6344 msgid "" "The documentation string of a class or function, or ``None`` if undefined." msgstr "" -#: ../../library/stdtypes.rst:6344 +#: ../../library/stdtypes.rst:6349 msgid "" "The :ref:`type parameters ` of generic classes, functions, and :" "ref:`type aliases `. For classes and functions that are not " "generic, this will be an empty tuple." msgstr "" -#: ../../library/stdtypes.rst:6354 +#: ../../library/stdtypes.rst:6359 msgid "Integer string conversion length limitation" msgstr "整數字串轉換長度限制" -#: ../../library/stdtypes.rst:6356 +#: ../../library/stdtypes.rst:6361 msgid "" "CPython has a global limit for converting between :class:`int` and :class:" "`str` to mitigate denial of service attacks. This limit *only* applies to " @@ -9359,7 +9365,7 @@ msgstr "" "進位的數值。十六進位、八進位,還有二進位的轉換則沒有長度限制。此限制值可以被" "調整。" -#: ../../library/stdtypes.rst:6361 +#: ../../library/stdtypes.rst:6366 msgid "" "The :class:`int` type in CPython is an arbitrary length number stored in " "binary form (commonly known as a \"bignum\"). There exists no algorithm that " @@ -9369,24 +9375,24 @@ msgid "" "value such as ``int('1' * 500_000)`` can take over a second on a fast CPU." msgstr "" -#: ../../library/stdtypes.rst:6368 +#: ../../library/stdtypes.rst:6373 msgid "" "Limiting conversion size offers a practical way to avoid :cve:`2020-10735`." msgstr "" -#: ../../library/stdtypes.rst:6370 +#: ../../library/stdtypes.rst:6375 msgid "" "The limit is applied to the number of digit characters in the input or " "output string when a non-linear conversion algorithm would be involved. " "Underscores and the sign are not counted towards the limit." msgstr "" -#: ../../library/stdtypes.rst:6374 +#: ../../library/stdtypes.rst:6379 msgid "" "When an operation would exceed the limit, a :exc:`ValueError` is raised:" msgstr "" -#: ../../library/stdtypes.rst:6376 +#: ../../library/stdtypes.rst:6381 msgid "" ">>> import sys\n" ">>> sys.set_int_max_str_digits(4300) # Illustrative, this is the default.\n" @@ -9410,7 +9416,7 @@ msgid "" ">>> assert int(hex(i_squared), base=16) == i*i # Hexadecimal is unlimited." msgstr "" -#: ../../library/stdtypes.rst:6396 +#: ../../library/stdtypes.rst:6401 msgid "" "The default limit is 4300 digits as provided in :data:`sys.int_info." "default_max_str_digits `. The lowest limit that can be " @@ -9418,11 +9424,11 @@ msgid "" "str_digits_check_threshold `." msgstr "" -#: ../../library/stdtypes.rst:6401 +#: ../../library/stdtypes.rst:6406 msgid "Verification:" msgstr "" -#: ../../library/stdtypes.rst:6403 +#: ../../library/stdtypes.rst:6408 msgid "" ">>> import sys\n" ">>> assert sys.int_info.default_max_str_digits == 4300, sys.int_info\n" @@ -9440,11 +9446,11 @@ msgstr "" "... '571186405732').to_bytes(53, 'big')\n" "..." -#: ../../library/stdtypes.rst:6416 +#: ../../library/stdtypes.rst:6421 msgid "Affected APIs" msgstr "受影響的 API" -#: ../../library/stdtypes.rst:6418 +#: ../../library/stdtypes.rst:6423 msgid "" "The limitation only applies to potentially slow conversions between :class:" "`int` and :class:`str` or :class:`bytes`:" @@ -9452,74 +9458,74 @@ msgstr "" "此限制僅適用於 :class:`int` 與 :class:`str` 或 :class:`bytes` 之間可能較慢的" "轉換:" -#: ../../library/stdtypes.rst:6421 +#: ../../library/stdtypes.rst:6426 msgid "``int(string)`` with default base 10." msgstr "``int(string)`` 以預設的 10 為底。" -#: ../../library/stdtypes.rst:6422 +#: ../../library/stdtypes.rst:6427 msgid "``int(string, base)`` for all bases that are not a power of 2." msgstr "``int(string, base)`` 用於所有非 2 冪次方的底。" -#: ../../library/stdtypes.rst:6423 +#: ../../library/stdtypes.rst:6428 msgid "``str(integer)``." msgstr "``str(integer)``。" -#: ../../library/stdtypes.rst:6424 +#: ../../library/stdtypes.rst:6429 msgid "``repr(integer)``." msgstr "``repr(integer)``。" -#: ../../library/stdtypes.rst:6425 +#: ../../library/stdtypes.rst:6430 msgid "" "any other string conversion to base 10, for example ``f\"{integer}\"``, " "``\"{}\".format(integer)``, or ``b\"%d\" % integer``." msgstr "" -#: ../../library/stdtypes.rst:6428 +#: ../../library/stdtypes.rst:6433 msgid "The limitations do not apply to functions with a linear algorithm:" msgstr "" -#: ../../library/stdtypes.rst:6430 +#: ../../library/stdtypes.rst:6435 msgid "``int(string, base)`` with base 2, 4, 8, 16, or 32." msgstr "``int(string, base)`` 以 2、4、8、16 或 32 為底。" -#: ../../library/stdtypes.rst:6431 +#: ../../library/stdtypes.rst:6436 msgid ":func:`int.from_bytes` and :func:`int.to_bytes`." msgstr ":func:`int.from_bytes` 和 :func:`int.to_bytes`。" -#: ../../library/stdtypes.rst:6432 +#: ../../library/stdtypes.rst:6437 msgid ":func:`hex`, :func:`oct`, :func:`bin`." msgstr ":func:`hex`、:func:`oct`、:func:`bin`。" -#: ../../library/stdtypes.rst:6433 +#: ../../library/stdtypes.rst:6438 msgid ":ref:`formatspec` for hex, octal, and binary numbers." msgstr ":ref:`formatspec` 用於十六進位、八進位和二進位數字。" -#: ../../library/stdtypes.rst:6434 +#: ../../library/stdtypes.rst:6439 msgid ":class:`str` to :class:`float`." msgstr ":class:`str` 轉換為 :class:`float`。" -#: ../../library/stdtypes.rst:6435 +#: ../../library/stdtypes.rst:6440 msgid ":class:`str` to :class:`decimal.Decimal`." msgstr ":class:`str` 轉換為 :class:`decimal.Decimal`。" -#: ../../library/stdtypes.rst:6438 +#: ../../library/stdtypes.rst:6443 msgid "Configuring the limit" msgstr "設定限制" -#: ../../library/stdtypes.rst:6440 +#: ../../library/stdtypes.rst:6445 msgid "" "Before Python starts up you can use an environment variable or an " "interpreter command line flag to configure the limit:" msgstr "" -#: ../../library/stdtypes.rst:6443 +#: ../../library/stdtypes.rst:6448 msgid "" ":envvar:`PYTHONINTMAXSTRDIGITS`, e.g. ``PYTHONINTMAXSTRDIGITS=640 python3`` " "to set the limit to 640 or ``PYTHONINTMAXSTRDIGITS=0 python3`` to disable " "the limitation." msgstr "" -#: ../../library/stdtypes.rst:6446 +#: ../../library/stdtypes.rst:6451 msgid "" ":option:`-X int_max_str_digits <-X>`, e.g. ``python3 -X " "int_max_str_digits=640``" @@ -9527,7 +9533,7 @@ msgstr "" ":option:`-X int_max_str_digits <-X>`,例如 ``python3 -X " "int_max_str_digits=640``" -#: ../../library/stdtypes.rst:6448 +#: ../../library/stdtypes.rst:6453 msgid "" ":data:`sys.flags.int_max_str_digits` contains the value of :envvar:" "`PYTHONINTMAXSTRDIGITS` or :option:`-X int_max_str_digits <-X>`. If both the " @@ -9536,38 +9542,38 @@ msgid "" "int_info.default_max_str_digits` was used during initialization." msgstr "" -#: ../../library/stdtypes.rst:6454 +#: ../../library/stdtypes.rst:6459 msgid "" "From code, you can inspect the current limit and set a new one using these :" "mod:`sys` APIs:" msgstr "" -#: ../../library/stdtypes.rst:6457 +#: ../../library/stdtypes.rst:6462 msgid "" ":func:`sys.get_int_max_str_digits` and :func:`sys.set_int_max_str_digits` " "are a getter and setter for the interpreter-wide limit. Subinterpreters have " "their own limit." msgstr "" -#: ../../library/stdtypes.rst:6461 +#: ../../library/stdtypes.rst:6466 msgid "" "Information about the default and minimum can be found in :data:`sys." "int_info`:" msgstr "" -#: ../../library/stdtypes.rst:6463 +#: ../../library/stdtypes.rst:6468 msgid "" ":data:`sys.int_info.default_max_str_digits ` is the compiled-" "in default limit." msgstr "" -#: ../../library/stdtypes.rst:6465 +#: ../../library/stdtypes.rst:6470 msgid "" ":data:`sys.int_info.str_digits_check_threshold ` is the lowest " "accepted value for the limit (other than 0 which disables it)." msgstr "" -#: ../../library/stdtypes.rst:6472 +#: ../../library/stdtypes.rst:6477 msgid "" "Setting a low limit *can* lead to problems. While rare, code exists that " "contains integer constants in decimal in their source that exceed the " @@ -9579,7 +9585,7 @@ msgid "" "constants is to convert them to ``0x`` hexadecimal form as it has no limit." msgstr "" -#: ../../library/stdtypes.rst:6481 +#: ../../library/stdtypes.rst:6486 msgid "" "Test your application thoroughly if you use a low limit. Ensure your tests " "run with the limit set early via the environment or flag so that it applies " @@ -9587,11 +9593,11 @@ msgid "" "to precompile ``.py`` sources to ``.pyc`` files." msgstr "" -#: ../../library/stdtypes.rst:6487 +#: ../../library/stdtypes.rst:6492 msgid "Recommended configuration" msgstr "建議的配置" -#: ../../library/stdtypes.rst:6489 +#: ../../library/stdtypes.rst:6494 msgid "" "The default :data:`sys.int_info.default_max_str_digits` is expected to be " "reasonable for most applications. If your application requires a different " @@ -9599,11 +9605,11 @@ msgid "" "as these APIs were added in security patch releases in versions before 3.12." msgstr "" -#: ../../library/stdtypes.rst:6494 +#: ../../library/stdtypes.rst:6499 msgid "Example::" msgstr "範例: ::" -#: ../../library/stdtypes.rst:6496 +#: ../../library/stdtypes.rst:6501 msgid "" ">>> import sys\n" ">>> if hasattr(sys, \"set_int_max_str_digits\"):\n" @@ -9625,38 +9631,38 @@ msgstr "" "... elif current_limit < lower_bound:\n" "... sys.set_int_max_str_digits(lower_bound)" -#: ../../library/stdtypes.rst:6506 +#: ../../library/stdtypes.rst:6511 msgid "If you need to disable it entirely, set it to ``0``." msgstr "" -#: ../../library/stdtypes.rst:6510 +#: ../../library/stdtypes.rst:6515 msgid "Footnotes" msgstr "註腳" -#: ../../library/stdtypes.rst:6511 +#: ../../library/stdtypes.rst:6516 msgid "" "Additional information on these special methods may be found in the Python " "Reference Manual (:ref:`customization`)." msgstr "" -#: ../../library/stdtypes.rst:6514 +#: ../../library/stdtypes.rst:6519 msgid "" "As a consequence, the list ``[1, 2]`` is considered equal to ``[1.0, 2.0]``, " "and similarly for tuples." msgstr "" -#: ../../library/stdtypes.rst:6517 +#: ../../library/stdtypes.rst:6522 msgid "They must have since the parser can't tell the type of the operands." msgstr "" -#: ../../library/stdtypes.rst:6519 +#: ../../library/stdtypes.rst:6524 msgid "" "Cased characters are those with general category property being one of " "\"Lu\" (Letter, uppercase), \"Ll\" (Letter, lowercase), or \"Lt\" (Letter, " "titlecase)." msgstr "" -#: ../../library/stdtypes.rst:6522 +#: ../../library/stdtypes.rst:6527 msgid "" "To format only a tuple you should therefore provide a singleton tuple whose " "only element is the tuple to be formatted." @@ -9669,13 +9675,13 @@ msgstr "built-in(內建)" #: ../../library/stdtypes.rst:13 ../../library/stdtypes.rst:332 #: ../../library/stdtypes.rst:409 ../../library/stdtypes.rst:1002 #: ../../library/stdtypes.rst:1192 ../../library/stdtypes.rst:1214 -#: ../../library/stdtypes.rst:1229 ../../library/stdtypes.rst:5224 -#: ../../library/stdtypes.rst:6226 +#: ../../library/stdtypes.rst:1229 ../../library/stdtypes.rst:5229 +#: ../../library/stdtypes.rst:6231 msgid "types" msgstr "type(型別)" #: ../../library/stdtypes.rst:34 ../../library/stdtypes.rst:1229 -#: ../../library/stdtypes.rst:5224 +#: ../../library/stdtypes.rst:5229 msgid "statement" msgstr "statement(陳述式)" @@ -9799,9 +9805,9 @@ msgstr "is not" #: ../../library/stdtypes.rst:1628 ../../library/stdtypes.rst:1758 #: ../../library/stdtypes.rst:3245 ../../library/stdtypes.rst:3264 #: ../../library/stdtypes.rst:3377 ../../library/stdtypes.rst:5013 -#: ../../library/stdtypes.rst:5224 ../../library/stdtypes.rst:5713 -#: ../../library/stdtypes.rst:5970 ../../library/stdtypes.rst:6145 -#: ../../library/stdtypes.rst:6190 +#: ../../library/stdtypes.rst:5229 ../../library/stdtypes.rst:5718 +#: ../../library/stdtypes.rst:5975 ../../library/stdtypes.rst:6150 +#: ../../library/stdtypes.rst:6195 msgid "object" msgstr "object(物件)" @@ -9893,9 +9899,9 @@ msgid "arithmetic" msgstr "arithmetic(算術)" #: ../../library/stdtypes.rst:251 ../../library/stdtypes.rst:1002 -#: ../../library/stdtypes.rst:1192 ../../library/stdtypes.rst:5224 -#: ../../library/stdtypes.rst:6197 ../../library/stdtypes.rst:6211 -#: ../../library/stdtypes.rst:6226 +#: ../../library/stdtypes.rst:1192 ../../library/stdtypes.rst:5229 +#: ../../library/stdtypes.rst:6202 ../../library/stdtypes.rst:6216 +#: ../../library/stdtypes.rst:6231 msgid "built-in function" msgstr "built-in function(內建函式)" @@ -9953,7 +9959,7 @@ msgstr "**" #: ../../library/stdtypes.rst:332 ../../library/stdtypes.rst:409 #: ../../library/stdtypes.rst:1002 ../../library/stdtypes.rst:1229 -#: ../../library/stdtypes.rst:5224 +#: ../../library/stdtypes.rst:5229 msgid "operations on" msgstr "operations on(操作於)" @@ -9962,7 +9968,7 @@ msgid "conjugate() (complex number method)" msgstr "conjugate()(複數方法)" #: ../../library/stdtypes.rst:351 ../../library/stdtypes.rst:1826 -#: ../../library/stdtypes.rst:3245 ../../library/stdtypes.rst:6226 +#: ../../library/stdtypes.rst:3245 ../../library/stdtypes.rst:6231 msgid "module" msgstr "模組" @@ -10030,7 +10036,7 @@ msgstr "values" msgid "iterator protocol" msgstr "iterator protocol(疊代器協定)" -#: ../../library/stdtypes.rst:899 ../../library/stdtypes.rst:5626 +#: ../../library/stdtypes.rst:899 ../../library/stdtypes.rst:5631 msgid "protocol" msgstr "protocol(協定)" @@ -10056,7 +10062,7 @@ msgstr "container(容器)" msgid "iteration over" msgstr "iteration over(疊代於)" -#: ../../library/stdtypes.rst:1002 ../../library/stdtypes.rst:5224 +#: ../../library/stdtypes.rst:1002 ../../library/stdtypes.rst:5229 msgid "len" msgstr "len" @@ -10131,8 +10137,8 @@ msgstr "list(串列)" msgid "bytearray" msgstr "bytearray(位元組陣列)" -#: ../../library/stdtypes.rst:1229 ../../library/stdtypes.rst:5224 -#: ../../library/stdtypes.rst:5970 ../../library/stdtypes.rst:6226 +#: ../../library/stdtypes.rst:1229 ../../library/stdtypes.rst:5229 +#: ../../library/stdtypes.rst:5975 ../../library/stdtypes.rst:6231 msgid "type" msgstr "type(型別)" @@ -10140,7 +10146,7 @@ msgstr "type(型別)" msgid "assignment" msgstr "assignment(賦值)" -#: ../../library/stdtypes.rst:1229 ../../library/stdtypes.rst:5224 +#: ../../library/stdtypes.rst:1229 ../../library/stdtypes.rst:5229 msgid "del" msgstr "del" @@ -10338,90 +10344,90 @@ msgstr "interpolation(插值)" msgid "set" msgstr "set(集合)" -#: ../../library/stdtypes.rst:5224 +#: ../../library/stdtypes.rst:5229 msgid "mapping" msgstr "mapping(對映)" -#: ../../library/stdtypes.rst:5224 +#: ../../library/stdtypes.rst:5229 msgid "dictionary" msgstr "dictionary(字典)" -#: ../../library/stdtypes.rst:5331 +#: ../../library/stdtypes.rst:5336 msgid "__missing__()" msgstr "__missing__()" -#: ../../library/stdtypes.rst:5626 +#: ../../library/stdtypes.rst:5631 msgid "context manager" msgstr "context manager(情境管理器)" -#: ../../library/stdtypes.rst:5626 +#: ../../library/stdtypes.rst:5631 msgid "context management protocol" msgstr "context management protocol(情境管理協定)" -#: ../../library/stdtypes.rst:5626 +#: ../../library/stdtypes.rst:5631 msgid "context management" msgstr "context management(情境管理)" -#: ../../library/stdtypes.rst:5701 +#: ../../library/stdtypes.rst:5706 msgid "annotation" msgstr "annotation(註記)" -#: ../../library/stdtypes.rst:5701 +#: ../../library/stdtypes.rst:5706 msgid "type annotation; type hint" msgstr "type annotation(型別註記);type hint(型別提示)" -#: ../../library/stdtypes.rst:5713 +#: ../../library/stdtypes.rst:5718 msgid "GenericAlias" msgstr "GenericAlias(泛型別名)" -#: ../../library/stdtypes.rst:5713 +#: ../../library/stdtypes.rst:5718 msgid "Generic" msgstr "Generic(泛型)" -#: ../../library/stdtypes.rst:5713 +#: ../../library/stdtypes.rst:5718 msgid "Alias" msgstr "Alias(別名)" -#: ../../library/stdtypes.rst:5970 +#: ../../library/stdtypes.rst:5975 msgid "Union" msgstr "Union(聯合)" -#: ../../library/stdtypes.rst:5970 +#: ../../library/stdtypes.rst:5975 msgid "union" msgstr "union(聯集)" -#: ../../library/stdtypes.rst:6145 +#: ../../library/stdtypes.rst:6150 msgid "method" msgstr "method(方法)" -#: ../../library/stdtypes.rst:6190 +#: ../../library/stdtypes.rst:6195 msgid "code" msgstr "code(程式碼)" -#: ../../library/stdtypes.rst:6190 +#: ../../library/stdtypes.rst:6195 msgid "code object" msgstr "code object(程式碼物件)" -#: ../../library/stdtypes.rst:6197 +#: ../../library/stdtypes.rst:6202 msgid "compile" msgstr "compile(編譯)" -#: ../../library/stdtypes.rst:6197 +#: ../../library/stdtypes.rst:6202 msgid "__code__ (function object attribute)" msgstr "__code__(函式物件屬性)" -#: ../../library/stdtypes.rst:6211 +#: ../../library/stdtypes.rst:6216 msgid "exec" msgstr "exec" -#: ../../library/stdtypes.rst:6211 +#: ../../library/stdtypes.rst:6216 msgid "eval" msgstr "eval" -#: ../../library/stdtypes.rst:6250 +#: ../../library/stdtypes.rst:6255 msgid "..." msgstr "..." -#: ../../library/stdtypes.rst:6250 +#: ../../library/stdtypes.rst:6255 msgid "ellipsis literal" msgstr "ellipsis literal(刪節號字面值)" diff --git a/library/threadsafety.po b/library/threadsafety.po index 8b6b8bdd9d0..5ee6166c0d1 100644 --- a/library/threadsafety.po +++ b/library/threadsafety.po @@ -6,7 +6,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.14\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2026-03-13 00:19+0000\n" +"POT-Creation-Date: 2026-03-13 17:06+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" @@ -419,7 +419,7 @@ msgid "" "result locked" msgstr "" -#: ../../library/threadsafety.rst:301 +#: ../../library/threadsafety.rst:301 ../../library/threadsafety.rst:434 msgid "" "Operations that involve multiple accesses, as well as iteration, are never " "atomic:" @@ -475,3 +475,166 @@ msgid "" "Consider external synchronization when sharing :class:`dict` instances " "across threads." msgstr "" + +#: ../../library/threadsafety.rst:350 +#, fuzzy +msgid "Thread safety for set objects" +msgstr "執行緒安全等級" + +#: ../../library/threadsafety.rst:352 +msgid "" +"The :func:`len` function is lock-free and :term:`atomic `." +msgstr "" + +#: ../../library/threadsafety.rst:354 +msgid "" +"The following read operation is lock-free. It does not block concurrent " +"modifications and may observe intermediate states from operations that hold " +"the per-object lock:" +msgstr "" + +#: ../../library/threadsafety.rst:358 +msgid "elem in s # set.__contains__" +msgstr "" + +#: ../../library/threadsafety.rst:363 +msgid "" +"This operation may compare elements using :meth:`~object.__eq__`, which can " +"execute arbitrary Python code. During such comparisons, the set may be " +"modified by another thread. For built-in types like :class:`str`, :class:" +"`int`, and :class:`float`, :meth:`!__eq__` does not release the underlying " +"lock during comparisons and this is not a concern." +msgstr "" + +#: ../../library/threadsafety.rst:369 +msgid "All other operations from here on hold the per-object lock." +msgstr "" + +#: ../../library/threadsafety.rst:371 +msgid "" +"Adding or removing a single element is safe to call from multiple threads " +"and will not corrupt the set:" +msgstr "" + +#: ../../library/threadsafety.rst:374 +msgid "" +"s.add(elem) # add element\n" +"s.remove(elem) # remove element, raise if missing\n" +"s.discard(elem) # remove element if present\n" +"s.pop() # remove and return arbitrary element" +msgstr "" + +#: ../../library/threadsafety.rst:382 +msgid "" +"These operations also compare elements, so the same :meth:`~object.__eq__` " +"considerations as above apply." +msgstr "" + +#: ../../library/threadsafety.rst:385 +msgid "" +"The :meth:`~set.copy` method returns a new object and holds the per-object " +"lock for the duration so that it is always atomic." +msgstr "" + +#: ../../library/threadsafety.rst:388 +msgid "" +"The :meth:`~set.clear` method holds the lock for its duration. Other threads " +"cannot observe elements being removed." +msgstr "" + +#: ../../library/threadsafety.rst:391 +msgid "" +"The following operations only accept :class:`set` or :class:`frozenset` as " +"operands and always lock both objects:" +msgstr "" + +#: ../../library/threadsafety.rst:394 +msgid "" +"s |= other # other must be set/frozenset\n" +"s &= other # other must be set/frozenset\n" +"s -= other # other must be set/frozenset\n" +"s ^= other # other must be set/frozenset\n" +"s & other # other must be set/frozenset\n" +"s | other # other must be set/frozenset\n" +"s - other # other must be set/frozenset\n" +"s ^ other # other must be set/frozenset" +msgstr "" + +#: ../../library/threadsafety.rst:406 +msgid "" +":meth:`set.update`, :meth:`set.union`, :meth:`set.intersection` and :meth:" +"`set.difference` can take multiple iterables as arguments. They all iterate " +"through all the passed iterables and do the following:" +msgstr "" + +#: ../../library/threadsafety.rst:410 +msgid ":meth:`set.update` and :meth:`set.union` lock both objects only when" +msgstr "" + +#: ../../library/threadsafety.rst:411 +msgid "" +"the other operand is a :class:`set`, :class:`frozenset`, or :class:`dict`." +msgstr "" + +#: ../../library/threadsafety.rst:412 +msgid ":meth:`set.intersection` and :meth:`set.difference` always try to lock" +msgstr "" + +#: ../../library/threadsafety.rst:413 +msgid "all objects." +msgstr "" + +#: ../../library/threadsafety.rst:415 +msgid ":meth:`set.symmetric_difference` tries to lock both objects." +msgstr "" + +#: ../../library/threadsafety.rst:417 +msgid "" +"The update variants of the above methods also have some differences between " +"them:" +msgstr "" + +#: ../../library/threadsafety.rst:420 +msgid ":meth:`set.difference_update` and :meth:`set.intersection_update` try" +msgstr "" + +#: ../../library/threadsafety.rst:421 +msgid "to lock all objects one-by-one." +msgstr "" + +#: ../../library/threadsafety.rst:422 +msgid "" +":meth:`set.symmetric_difference_update` only locks the arguments if it is" +msgstr "" + +#: ../../library/threadsafety.rst:423 +msgid "of type :class:`set`, :class:`frozenset`, or :class:`dict`." +msgstr "" + +#: ../../library/threadsafety.rst:425 +msgid "The following methods always try to lock both objects:" +msgstr "" + +#: ../../library/threadsafety.rst:427 +msgid "" +"s.isdisjoint(other) # both locked\n" +"s.issubset(other) # both locked\n" +"s.issuperset(other) # both locked" +msgstr "" + +#: ../../library/threadsafety.rst:437 +msgid "" +"# NOT atomic: check-then-act\n" +"if elem in s:\n" +" s.remove(elem)\n" +"\n" +"# NOT thread-safe: iteration while modifying\n" +"for elem in s:\n" +" process(elem) # another thread may modify s" +msgstr "" + +#: ../../library/threadsafety.rst:448 +msgid "" +"Consider external synchronization when sharing :class:`set` instances across " +"threads. See :ref:`freethreading-python-howto` for more information." +msgstr "" diff --git a/tutorial/errors.po b/tutorial/errors.po index 3a2853974f9..31ca1f856e6 100644 --- a/tutorial/errors.po +++ b/tutorial/errors.po @@ -9,7 +9,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.14\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2025-09-08 15:25+0800\n" +"POT-Creation-Date: 2026-03-13 17:06+0000\n" "PO-Revision-Date: 2022-10-24 14:54+0800\n" "Last-Translator: Steven Hsu \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" @@ -141,12 +141,12 @@ msgstr "" msgid "" "The last line of the error message indicates what happened. Exceptions come " "in different types, and the type is printed as part of the message: the " -"types in the example are :exc:`ZeroDivisionError`, :exc:`NameError` " -"and :exc:`TypeError`. The string printed as the exception type is the name " -"of the built-in exception that occurred. This is true for all built-in " -"exceptions, but need not be true for user-defined exceptions (although it is " -"a useful convention). Standard exception names are built-in identifiers (not " -"reserved keywords)." +"types in the example are :exc:`ZeroDivisionError`, :exc:`NameError` and :exc:" +"`TypeError`. The string printed as the exception type is the name of the " +"built-in exception that occurred. This is true for all built-in exceptions, " +"but need not be true for user-defined exceptions (although it is a useful " +"convention). Standard exception names are built-in identifiers (not reserved " +"keywords)." msgstr "" "錯誤訊息的最後一行指示發生了什麼事。例外有不同的類型,而類型名稱會作為訊息的" "一部份被印出。範例中的例外類型為::exc:`ZeroDivisionError`、:exc:`NameError` " @@ -185,10 +185,10 @@ msgstr "處理例外" msgid "" "It is possible to write programs that handle selected exceptions. Look at " "the following example, which asks the user for input until a valid integer " -"has been entered, but allows the user to interrupt the program " -"(using :kbd:`Control-C` or whatever the operating system supports); note " -"that a user-generated interruption is signalled by raising " -"the :exc:`KeyboardInterrupt` exception. ::" +"has been entered, but allows the user to interrupt the program (using :kbd:" +"`Control-C` or whatever the operating system supports); note that a user-" +"generated interruption is signalled by raising the :exc:`KeyboardInterrupt` " +"exception. ::" msgstr "" "編寫程式處理選定的例外是可行的。以下範例會要求使用者輸入內容,直到有效的整數" "被輸入為止,但它允許使用者中斷程式(使用 :kbd:`Control-C` 或作業系統支援的指" @@ -219,16 +219,16 @@ msgstr ":keyword:`try` 陳述式運作方式如下。" #: ../../tutorial/errors.rst:105 msgid "" -"First, the *try clause* (the statement(s) between the :keyword:`try` " -"and :keyword:`except` keywords) is executed." +"First, the *try clause* (the statement(s) between the :keyword:`try` and :" +"keyword:`except` keywords) is executed." msgstr "" "首先,執行 *try 子句*\\ (:keyword:`try` 和 :keyword:`except` 關鍵字之間的陳" "述式)。" #: ../../tutorial/errors.rst:108 msgid "" -"If no exception occurs, the *except clause* is skipped and execution of " -"the :keyword:`try` statement is finished." +"If no exception occurs, the *except clause* is skipped and execution of the :" +"keyword:`try` statement is finished." msgstr "" "如果沒有發生例外,則 *except 子句*\\ 會被跳過,:keyword:`try` 陳述式執行完" "畢。" @@ -251,18 +251,18 @@ msgid "" "handler is found, it is an *unhandled exception* and execution stops with an " "error message." msgstr "" -"如果發生的例外未符合 *except 子句* 中的例外名稱,則將其傳遞到外層" -"的 :keyword:`try` 陳述式;如果仍無法找到處理者,則它是一個\\ *未處理例外 " -"(unhandled exception)*,執行將停止,並顯示錯誤訊息。" +"如果發生的例外未符合 *except 子句* 中的例外名稱,則將其傳遞到外層的 :keyword:" +"`try` 陳述式;如果仍無法找到處理者,則它是一個\\ *未處理例外 (unhandled " +"exception)*,執行將停止,並顯示錯誤訊息。" #: ../../tutorial/errors.rst:120 +#, fuzzy msgid "" "A :keyword:`try` statement may have more than one *except clause*, to " "specify handlers for different exceptions. At most one handler will be " "executed. Handlers only handle exceptions that occur in the corresponding " "*try clause*, not in other handlers of the same :keyword:`!try` statement. " -"An *except clause* may name multiple exceptions as a parenthesized tuple, " -"for example::" +"An *except clause* may name multiple exceptions, for example::" msgstr "" ":keyword:`try` 陳述式可以有不只一個 *except 子句*,為不同的例外指定處理者,而" "最多只有一個處理者會被執行。處理者只處理對應的 try 子句中發生的例外,而不會處" @@ -270,8 +270,9 @@ msgstr "" "用一組括號內的 tuple 列舉多個例外,例如: ::" #: ../../tutorial/errors.rst:126 +#, fuzzy msgid "" -"... except (RuntimeError, TypeError, NameError):\n" +"... except RuntimeError, TypeError, NameError:\n" "... pass" msgstr "" "... except (RuntimeError, TypeError, NameError):\n" @@ -356,8 +357,8 @@ msgid "" "explicitly accessing ``.args``. ::" msgstr "" "*except 子句*\\ 可以在例外名稱後面指定一個變數。這個變數被綁定到一個例外實例 " -"(instance),其引數通常儲存在 ``args`` 屬性中。為了方便,內建例外型別定義" -"了 :meth:`~object.__str__` 以印出所有引數而不需顯式地取用 ``.args``: ::" +"(instance),其引數通常儲存在 ``args`` 屬性中。為了方便,內建例外型別定義了 :" +"meth:`~object.__str__` 以印出所有引數而不需顯式地取用 ``.args``: ::" #: ../../tutorial/errors.rst:166 msgid "" @@ -410,16 +411,15 @@ msgid "" "subclasses, :exc:`Exception`, is the base class of all the non-fatal " "exceptions. Exceptions which are not subclasses of :exc:`Exception` are not " "typically handled, because they are used to indicate that the program should " -"terminate. They include :exc:`SystemExit` which is raised " -"by :meth:`sys.exit` and :exc:`KeyboardInterrupt` which is raised when a user " -"wishes to interrupt the program." +"terminate. They include :exc:`SystemExit` which is raised by :meth:`sys." +"exit` and :exc:`KeyboardInterrupt` which is raised when a user wishes to " +"interrupt the program." msgstr "" ":exc:`BaseException` 是由全部的例外所共用的 base class。它的 subclass(子類" "別)之一,:exc:`Exception`,則是所有非嚴重例外 (non-fatal exception) 的 base " "class。有些例外不是 :exc:`Exception` 的 subclass,而它們通常不會被處理,因為" -"它們是用來指示程式應該終止。這些例外包括了由 :meth:`sys.exit` 所引發" -"的 :exc:`SystemExit`,以及當使用者想要中斷程式時所引發" -"的 :exc:`KeyboardInterrupt`。" +"它們是用來指示程式應該終止。這些例外包括了由 :meth:`sys.exit` 所引發的 :exc:" +"`SystemExit`,以及當使用者想要中斷程式時所引發的 :exc:`KeyboardInterrupt`。" #: ../../tutorial/errors.rst:194 msgid "" @@ -591,8 +591,8 @@ msgid "" "handle it, a simpler form of the :keyword:`raise` statement allows you to re-" "raise the exception::" msgstr "" -"如果你只想判斷是否引發了例外,但並不打算處理它,則可以使用簡單" -"的 :keyword:`raise` 陳述式來重新引發該例外: ::" +"如果你只想判斷是否引發了例外,但並不打算處理它,則可以使用簡單的 :keyword:" +"`raise` 陳述式來重新引發該例外: ::" #: ../../tutorial/errors.rst:277 msgid "" @@ -673,9 +673,8 @@ msgstr "" #: ../../tutorial/errors.rst:317 msgid "" -"To indicate that an exception is a direct consequence of another, " -"the :keyword:`raise` statement allows an optional :keyword:`from` " -"clause::" +"To indicate that an exception is a direct consequence of another, the :" +"keyword:`raise` statement allows an optional :keyword:`from` clause::" msgstr "" "為了表明一個例外是另一個例外直接造成的結果,:keyword:`raise` 陳述式容許一個選" "擇性的 :keyword:`from` 子句: ::" @@ -783,8 +782,8 @@ msgid "" "indirectly." msgstr "" "程式可以透過建立新的例外 class 來命名自己的例外(深入了解 Python class,詳見" -"\\ :ref:`tut-classes`\\ )。不論是直接還是間接地,例外通常應該" -"從 :exc:`Exception` class 衍生出來。" +"\\ :ref:`tut-classes`\\ )。不論是直接還是間接地,例外通常應該從 :exc:" +"`Exception` class 衍生出來。" #: ../../tutorial/errors.rst:372 msgid "" @@ -853,10 +852,10 @@ msgid "" "statement produces an exception. The following points discuss more complex " "cases when an exception occurs:" msgstr "" -"如果 :keyword:`finally` 子句存在,則 :keyword:`!finally` 子句會" -"是 :keyword:`try` 陳述式結束前執行的最後一項任務。不論 :keyword:`!try` 陳述式" -"是否產生例外,都會執行 :keyword:`!finally` 子句。以下幾點將探討例外發生時,比" -"較複雜的情況:" +"如果 :keyword:`finally` 子句存在,則 :keyword:`!finally` 子句會是 :keyword:" +"`try` 陳述式結束前執行的最後一項任務。不論 :keyword:`!try` 陳述式是否產生例" +"外,都會執行 :keyword:`!finally` 子句。以下幾點將探討例外發生時,比較複雜的情" +"況:" #: ../../tutorial/errors.rst:409 msgid "" @@ -865,55 +864,56 @@ msgid "" "not handled by an :keyword:`!except` clause, the exception is re-raised " "after the :keyword:`!finally` clause has been executed." msgstr "" -"若一個例外發生於 :keyword:`!try` 子句的執行過程,則該例外會被某" -"個 :keyword:`except` 子句處理。如果該例外沒有被 :keyword:`!except` 子句處理," -"它會在 :keyword:`!finally` 子句執行後被重新引發。" +"若一個例外發生於 :keyword:`!try` 子句的執行過程,則該例外會被某個 :keyword:" +"`except` 子句處理。如果該例外沒有被 :keyword:`!except` 子句處理,它會在 :" +"keyword:`!finally` 子句執行後被重新引發。" #: ../../tutorial/errors.rst:415 msgid "" -"An exception could occur during execution of an :keyword:`!except` " -"or :keyword:`!else` clause. Again, the exception is re-raised after " -"the :keyword:`!finally` clause has been executed." +"An exception could occur during execution of an :keyword:`!except` or :" +"keyword:`!else` clause. Again, the exception is re-raised after the :keyword:" +"`!finally` clause has been executed." msgstr "" "一個例外可能發生於 :keyword:`!except` 或 :keyword:`!else` 子句的執行過程。同" "樣地,該例外會在 :keyword:`!finally` 子句執行後被重新引發。" #: ../../tutorial/errors.rst:419 msgid "" -"If the :keyword:`!finally` clause executes " -"a :keyword:`break`, :keyword:`continue` or :keyword:`return` statement, " -"exceptions are not re-raised. This can be confusing and is therefore " -"discouraged. From version 3.14 the compiler emits a :exc:`SyntaxWarning` for " -"it (see :pep:`765`)." +"If the :keyword:`!finally` clause executes a :keyword:`break`, :keyword:" +"`continue` or :keyword:`return` statement, exceptions are not re-raised. " +"This can be confusing and is therefore discouraged. From version 3.14 the " +"compiler emits a :exc:`SyntaxWarning` for it (see :pep:`765`)." msgstr "" -"如果 :keyword:`!finally` 子句執行 :keyword:`break`、:keyword:`continue` " -"或 :keyword:`return` 陳述式,則例外不會被重新引發。這可能會令人困惑,因此不建議這麼做。" -"從 3.14 版本開始,編譯器會為此發出 :exc:`SyntaxWarning`\\ (詳見 :pep:`765`)。" +"如果 :keyword:`!finally` 子句執行 :keyword:`break`、:keyword:`continue` 或 :" +"keyword:`return` 陳述式,則例外不會被重新引發。這可能會令人困惑,因此不建議這" +"麼做。從 3.14 版本開始,編譯器會為此發出 :exc:`SyntaxWarning`\\ (詳見 :pep:" +"`765`)。" #: ../../tutorial/errors.rst:425 msgid "" -"If the :keyword:`!try` statement reaches " -"a :keyword:`break`, :keyword:`continue` or :keyword:`return` statement, " -"the :keyword:`!finally` clause will execute just prior to the :keyword:`!" -"break`, :keyword:`!continue` or :keyword:`!return` statement's execution." +"If the :keyword:`!try` statement reaches a :keyword:`break`, :keyword:" +"`continue` or :keyword:`return` statement, the :keyword:`!finally` clause " +"will execute just prior to the :keyword:`!break`, :keyword:`!continue` or :" +"keyword:`!return` statement's execution." msgstr "" -"如果 :keyword:`!try` 陳述式遇到 :keyword:`break`、:keyword:`continue` " -"或 :keyword:`return` 陳述式,則 :keyword:`!finally` 子句會在執行 :keyword:`!" +"如果 :keyword:`!try` 陳述式遇到 :keyword:`break`、:keyword:`continue` 或 :" +"keyword:`return` 陳述式,則 :keyword:`!finally` 子句會在執行 :keyword:`!" "break`、:keyword:`!continue` 或 :keyword:`!return` 陳述式之前先執行。" #: ../../tutorial/errors.rst:431 msgid "" "If a :keyword:`!finally` clause includes a :keyword:`!return` statement, the " -"returned value will be the one from the :keyword:`!finally` " -"clause's :keyword:`!return` statement, not the value from the :keyword:`!" -"try` clause's :keyword:`!return` statement. This can be confusing and is " -"therefore discouraged. From version 3.14 the compiler emits " -"a :exc:`SyntaxWarning` for it (see :pep:`765`)." +"returned value will be the one from the :keyword:`!finally` clause's :" +"keyword:`!return` statement, not the value from the :keyword:`!try` " +"clause's :keyword:`!return` statement. This can be confusing and is " +"therefore discouraged. From version 3.14 the compiler emits a :exc:" +"`SyntaxWarning` for it (see :pep:`765`)." msgstr "" "如果 :keyword:`!finally` 子句中包含 :keyword:`!return` 陳述式,則回傳值會是來" -"自 :keyword:`!finally` 子句的 :keyword:`!return` 陳述式的回傳值,而不是來" -"自 :keyword:`!try` 子句的 :keyword:`!return` 陳述式的回傳值。這可能會令人困惑,因此不建議這麼做。" -"從 3.14 版本開始,編譯器會為此發出 :exc:`SyntaxWarning`\\ (詳見 :pep:`765`)。" +"自 :keyword:`!finally` 子句的 :keyword:`!return` 陳述式的回傳值,而不是來自 :" +"keyword:`!try` 子句的 :keyword:`!return` 陳述式的回傳值。這可能會令人困惑,因" +"此不建議這麼做。從 3.14 版本開始,編譯器會為此發出 :exc:`SyntaxWarning`\\ " +"(詳見 :pep:`765`)。" #: ../../tutorial/errors.rst:439 msgid "For example::" @@ -1002,8 +1002,8 @@ msgstr "" #: ../../tutorial/errors.rst:479 msgid "" "As you can see, the :keyword:`finally` clause is executed in any event. " -"The :exc:`TypeError` raised by dividing two strings is not handled by " -"the :keyword:`except` clause and therefore re-raised after the :keyword:`!" +"The :exc:`TypeError` raised by dividing two strings is not handled by the :" +"keyword:`except` clause and therefore re-raised after the :keyword:`!" "finally` clause has been executed." msgstr "" "如你所見,:keyword:`finally` 子句在任何情況下都會被執行。兩個字串相除所引發" @@ -1051,9 +1051,9 @@ msgid "" "correctly. ::" msgstr "" "這段程式碼的問題在於,執行完該程式碼後,它讓檔案在一段不確定的時間內處於開啟" -"狀態。在簡單腳本中這不是問題,但對於較大的應用程式來說可能會是個問" -"題。:keyword:`with` 陳述式讓物件(例如檔案)在被使用時,能保證它們總是及時、" -"正確地被清理。 ::" +"狀態。在簡單腳本中這不是問題,但對於較大的應用程式來說可能會是個問題。:" +"keyword:`with` 陳述式讓物件(例如檔案)在被使用時,能保證它們總是及時、正確地" +"被清理。 ::" #: ../../tutorial/errors.rst:508 msgid "" From 91134192d660d392e5ff50e9c9f6cb10b22e15cf Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 15 Mar 2026 00:24:08 +0000 Subject: [PATCH 2/2] sync with cpython 1749b3c6 --- library/stdtypes.po | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/library/stdtypes.po b/library/stdtypes.po index 12e088e8f99..c47db3f05a5 100644 --- a/library/stdtypes.po +++ b/library/stdtypes.po @@ -9,7 +9,7 @@ msgid "" msgstr "" "Project-Id-Version: Python 3.14\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2026-03-13 17:06+0000\n" +"POT-Creation-Date: 2026-03-15 00:22+0000\n" "PO-Revision-Date: 2022-06-12 15:22+0800\n" "Last-Translator: Matt Wang \n" "Language-Team: Chinese - TAIWAN (https://github.com/python/python-docs-zh-" @@ -2098,10 +2098,11 @@ msgid "Mutable sequence types also support the following methods:" msgstr "可變序列型別也支援以下方法:" #: ../../library/stdtypes.rst:1289 +#, fuzzy msgid "" -"Append *value* to the end of the sequence This is equivalent to writing " +"Append *value* to the end of the sequence. This is equivalent to writing " "``seq[len(seq):len(seq)] = [value]``." -msgstr "" +msgstr "移除 *sequence* 中的所有項目,這和 ``del sequence[:]`` 相同。" #: ../../library/stdtypes.rst:1301 msgid ""