Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Payon <[email protected]>
  • Loading branch information
mattwang44 and ken71301 committed Aug 25, 2024
1 parent 5a5f094 commit ff862d0
Showing 1 changed file with 41 additions and 39 deletions.
80 changes: 41 additions & 39 deletions library/functools.po
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ msgid ""
"Simple lightweight unbounded function cache. Sometimes called `\"memoize\" "
"<https://en.wikipedia.org/wiki/Memoization>`_."
msgstr ""
"簡單的輕量級無界函式快取 (Simple lightweight unbounded function cache)。有時"
"稱之為 `\"memoize\"(記憶化) <https://en.wikipedia.org/wiki/Memoization>`_。"
"簡單的輕量級無繫結函式快取 (Simple lightweight unbounded function cache)。有"
"時稱之為 `\"memoize\"(記憶化) <https://en.wikipedia.org/wiki/"
"Memoization>`_。"

#: ../../library/functools.rst:34
msgid ""
Expand Down Expand Up @@ -90,8 +91,8 @@ msgid ""
"computed properties of instances that are otherwise effectively immutable."
msgstr ""
"將類別的一個方法轉換為屬性 (property),其值會計算一次,然後在實例的生命週期內"
"快取為普通屬性。類似 :func:`property`,但增加了快取機制。對於實質上幾乎是不可"
" (immutable) 的實例,針對其需要繁重計算的屬性會很有用。"
"快取為普通屬性。類似 :func:`property`,但增加了快取機制。對於除使用該裝飾器的"
"屬性外實質上幾乎是不可變 (immutable) 的實例,針對其所需要繁重計算會很有用。"

#: ../../library/functools.rst:70 ../../library/functools.rst:142
#: ../../library/functools.rst:383
Expand Down Expand Up @@ -138,8 +139,9 @@ msgid ""
msgstr ""
"*cached_property* 無法防止多執行緒使用中可能出現的競爭條件 (race condition)。"
"getter 函式可以在同一個實例上運行多次,最後一次運行會設定快取的值。所以快取的"
"屬性最好是冪等的 (idempotent),或者在一個實例上運行多次不會有害。如果同步是必"
"要的,請在裝飾的 getter 函式內部或在快取的屬性存取周圍實作必要的鎖。"
"屬性最好是冪等的 (idempotent),或者在一個實例上運行多次不會有害,就不會有問"
"題。如果同步是必要的,請在裝飾的 getter 函式內部或在快取的屬性存取周圍實作必"
"要的鎖。"

#: ../../library/functools.rst:102
msgid ""
Expand All @@ -159,7 +161,7 @@ msgid ""
"``__slots__`` without including ``__dict__`` as one of the defined slots (as "
"such classes don't provide a ``__dict__`` attribute at all)."
msgstr ""
"此外,此裝飾器要求每個實例上的 ``__dict__`` 屬性是可變映射 (mutable "
"此外,此裝飾器要求每個實例上的 ``__dict__`` 屬性是可變對映 (mutable "
"mapping)。這意味著它不適用於某些型別,例如元類別 (metaclass)(因為型別實例上"
"的 ``__dict__`` 屬性是類別命名空間的唯讀代理),以及那些指定 ``__slots__`` 而"
"不包含 ``__dict__`` 的型別作為有定義的插槽之一(因為此種類別根本不提供 "
Expand All @@ -173,7 +175,7 @@ msgid ""
"cache-method-calls` for more details on how this differs from :func:"
"`cached_property`."
msgstr ""
"如果可變映射不可用或需要金鑰共享以節省空間,則也可以透過在 :func:`lru_cache` "
"如果可變對映不可用或需要金鑰共享以節省空間,則也可以透過在 :func:`lru_cache` "
"之上堆疊 :func:`property` 來實作類似於 :func:`cached_property` 的效果。請參閱"
"\\ :ref:`faq-cache-method-calls`\\ 以了解有關這與 :func:`cached_property` 間"
"不同之處的更多詳細資訊。"
Expand Down Expand Up @@ -203,7 +205,7 @@ msgstr ""
"將舊式比較函式轉換為\\ :term:`鍵函式 <key function>`,能與接受鍵函式的工具一"
"起使用(例如 :func:`sorted`、:func:`min`、:func:`max`、:func:`heapq."
"nlargest`、:func:`heapq.nsmallest`、:func:`itertools.groupby`)。此函式主要作"
"為轉換工具,用於自有支援使用比較函式的 Python 2 轉換成的程式。"
"為轉換工具,用於從有支援使用比較函式的 Python 2 轉換成的程式。"

#: ../../library/functools.rst:137
msgid ""
Expand All @@ -227,8 +229,8 @@ msgid ""
"*maxsize* most recent calls. It can save time when an expensive or I/O "
"bound function is periodically called with the same arguments."
msgstr ""
"裝飾器以記憶化可呼叫物件來包裝函式,最多可省去 *maxsize* 個最近的呼叫。當使用"
"相同引數定期呼叫繁重的或 I/O 密集的函式時,它可以節省時間。"
"以記憶化可呼叫物件來包裝函式的裝飾器,最多可省去 *maxsize* 個最近的呼叫。當使"
"用相同引數定期呼叫繁重的或 I/O 密集的函式時,它可以節省時間。"

#: ../../library/functools.rst:166
msgid ""
Expand All @@ -245,8 +247,8 @@ msgid ""
"differ in their keyword argument order and may have two separate cache "
"entries."
msgstr ""
"不同的引數模式可以被認為是具有不同快取條目的呼叫。例如,``f(a=1, b=2)`` "
"``f(b=2, a=1)`` 的關鍵字引數順序不同,並且可能有兩個單獨的快取條目。"
"不同的引數模式可以被認為是具有不同快取條目的不同呼叫。例如,``f(a=1, b=2)`` "
"``f(b=2, a=1)`` 的關鍵字引數順序不同,並且可能有兩個不同的快取條目。"

#: ../../library/functools.rst:174
msgid ""
Expand Down Expand Up @@ -363,9 +365,9 @@ msgid ""
"objects on each call (such as generators and async functions), or impure "
"functions such as time() or random()."
msgstr ""
"一般來說,僅當你想要重複使用先前計算的值時才應使用 LRU 快取。因此,快取具有副"
"作用的函式、需要在每次呼叫時建立不同可變物件的函式(例如產生器和非同步函式)"
"或不純函式(impure function,例如 time() 或 random())是沒有意義的。"
"一般來說,僅當你想要重複使用先前計算的值時才應使用 LRU 快取。因此,快取具有 "
"side-effects 的函式、需要在每次呼叫時建立不同可變物件的函式(例如產生器和非同"
"步函式)或不純函式(impure function,例如 time() 或 random())是沒有意義的。"

#: ../../library/functools.rst:233
msgid "Example of an LRU cache for static web content::"
Expand Down Expand Up @@ -409,7 +411,7 @@ msgid ""
"method."
msgstr ""
"類別必須定義 :meth:`__lt__`、:meth:`__le__`、:meth:`__gt__` 或 :meth:"
"`__ge__` 之一。此外,該類別應該提供 :meth:`__eq__` 方法。"
"`__ge__` 其中之一。此外,該類別應該提供 :meth:`__eq__` 方法。"

#: ../../library/functools.rst:311
msgid ""
Expand All @@ -420,9 +422,9 @@ msgid ""
"rich comparison methods instead is likely to provide an easy speed boost."
msgstr ""
"雖然此裝飾器可以輕鬆建立能好好運作的完全有序型別 (totally ordered types),但"
"它\\ *確實*\\ 以衍生比較方法的執行速度較慢和堆疊追蹤 (stack trace) 較複雜為代"
"。如果效能基準測試顯示這是給定應用程式的效能瓶頸,那麼實作全部六種 rich "
"comparison 方法通常能輕鬆地提升速度。"
"它\\ *的確*\\ 以衍生比較方法的執行速度較慢和堆疊追蹤 (stack trace) 較複雜做為"
"其代價。如果效能基準測試顯示這是給定應用程式的效能瓶頸,那麼實作全部六種 "
"rich comparison 方法通常能輕鬆地提升速度。"

#: ../../library/functools.rst:320
msgid ""
Expand All @@ -439,7 +441,7 @@ msgstr ""
msgid ""
"Returning ``NotImplemented`` from the underlying comparison function for "
"unrecognised types is now supported."
msgstr "現在支援從底層對於未識別型別的比較函式回傳 NotImplemented。"
msgstr "現在支援從底層對於未識別型別的比較函式回傳 ``NotImplemented``。"

#: ../../library/functools.rst:333
msgid ""
Expand All @@ -449,9 +451,9 @@ msgid ""
"appended to *args*. If additional keyword arguments are supplied, they "
"extend and override *keywords*. Roughly equivalent to::"
msgstr ""
"回傳一個新的 :ref:`partial 物件 <partial-objects>`,它在呼叫時的行為類似於使"
"用位置引數 *args* 和關鍵字引數 *keywords* 呼叫的 *func*。如果向呼叫提供更多引"
",它們將被附加到 *args*。如果提供了額外的關鍵字引數,它們會擴充並覆寫 "
"回傳一個新的 :ref:`partial 物件 <partial-objects>`,它在被呼叫時的行為類似於"
"使用位置引數 *args* 和關鍵字引數 *keywords* 呼叫的 *func*。如果向呼叫提供更多"
"引數,它們將被附加到 *args*。如果提供了額外的關鍵字引數,它們會擴充並覆寫 "
"*keywords*。大致相當於: ::"

#: ../../library/functools.rst:349
Expand Down Expand Up @@ -493,8 +495,8 @@ msgid ""
msgstr ""
"當 *func* 是描述器時(例如普通的 Python 函式、:func:`classmethod`、:func:"
"`staticmethod`、:func:`abstractmethod` 或 :class:`partialmethod` 的另一個實"
"例),``__get__`` 的呼叫將被委託 (delegated) 給底層描述器,且一個適當的 :ref:"
"`partial 物件 <partial-objects>`\\ 會被作為結果回傳。"
"例),``__get__`` 的呼叫將被委託 (delegated) 給底層描述器,且一個適當的 :"
"ref:`partial 物件 <partial-objects>`\\ 會被作為結果回傳。"

#: ../../library/functools.rst:377
msgid ""
Expand All @@ -505,9 +507,9 @@ msgid ""
"`partialmethod` constructor."
msgstr ""
"當 *func* 是非描述器可呼叫物件 (non-descriptor callable) 時,會動態建立適當的"
"繫結方法 (bound method)。當用作方法時,其行為類似於普通的 Python 函式:"
"*self* 引數將作為第一個位置引數插入,會在提供給 :class:`partialmethod` 建構函"
"式的 *args* 和 *keywords* 之前。"
"繫結方法 (bound method)。當被作為方法使用時,其行為類似於普通的 Python 函式:"
"*self* 引數將作為第一個位置引數插入,甚至會在提供給 :class:`partialmethod` "
"構函式的 *args* 和 *keywords* 的前面。"

#: ../../library/functools.rst:408
msgid ""
Expand All @@ -526,7 +528,7 @@ msgstr ""
"算出 ``((((1+2)+3)+4)+5)``。左邊的引數 *x* 是累積值,右邊的引數 *y* 是來自 "
"*iterable* 的更新值。如果可選的 *initializer* 存在,則在計算中會將其放置在可"
"疊代物件的項目之前,並在可疊代物件為空時作為預設值。如果未給定 *initializer* "
"且 *iterable* 僅包含一個項目,則傳回第一個項目。"
"且 *iterable* 僅包含一個項目,則回傳第一個項目。"

#: ../../library/functools.rst:417
msgid "Roughly equivalent to::"
Expand Down Expand Up @@ -565,7 +567,7 @@ msgid ""
"functions annotated with types, the decorator will infer the type of the "
"first argument automatically::"
msgstr ""
"若要為函式新增重載實作,請使用泛型函式的 :func:`register` 屬性,該屬性可用作"
"若要為函式新增過載實作,請使用泛型函式的 :func:`register` 屬性,該屬性可用作"
"裝飾器。對於以型別來註釋的函式,裝飾器將自動推斷第一個引數的型別: ::"

#: ../../library/functools.rst:466
Expand Down Expand Up @@ -675,10 +677,10 @@ msgid ""
"Here is the ``Negator`` class with the ``neg`` methods bound to the class, "
"rather than an instance of the class::"
msgstr ""
"``@singledispatchmethod`` 支援與其他裝飾器嵌套 (nest),例如 :func:"
"`@classmethod<classmethod>`。請注意,為了允許 ``dispatcher.register``,"
"``singledispatchmethod`` 必須是\\ *最外面的*\\ 裝飾器。這是 ``Negator`` 類"
",其 ``neg`` 方法繫結到該類別,而不是該類別的實例: ::"
"``@singledispatchmethod`` 支援與其他裝飾器巢狀使用 (nesting),例如 :func:"
"`@classmethod<classmethod>`。請注意,為了使 ``dispatcher.register`` 可用,"
"``singledispatchmethod`` 必須是\\ *最外面的*\\ 裝飾器。以下範例是 "
"``Negator`` 類別,其 ``neg`` 方法繫結到該類別,而不是該類別的實例: ::"

#: ../../library/functools.rst:632
msgid ""
Expand Down Expand Up @@ -706,7 +708,7 @@ msgstr ""
"始函式的哪些屬性直接賦值給包裝函式上的匹配屬性,以及包裝函式的哪些屬性使用原"
"始函式中的對應屬性進行更新。這些引數的預設值是模組層級的常數 "
"``WRAPPER_ASSIGNMENTS``\\ (它賦值給包裝函式的 ``__module__``、``__name__``、"
"``__qualname__``、``__annotations__`` 和 ``__doc__`` 文件字串 (docstring))和"
"``__qualname__``、``__annotations__`` 和 ``__doc__`` 文件字串 (docstring)和 "
"``WRAPPER_UPDATES``\\ (更新包裝器函式的 ``__dict__``,即實例字典)。"

#: ../../library/functools.rst:652
Expand All @@ -716,9 +718,9 @@ msgid ""
"this function automatically adds a ``__wrapped__`` attribute to the wrapper "
"that refers to the function being wrapped."
msgstr ""
"為了允許出於自我檢查和其他目的所對原始函式的存取(例如繞過快取裝飾器,如 :"
"func:`lru_cache`),此函式會自動向包裝器新增 ``__wrapped__`` 屬性,該包裝器參"
"照被包裝的函式。"
"為了允許出於內省 (introspection) 和其他目的所對原始函式的存取(例如繞過快取裝"
"飾器,如 :func:`lru_cache`),此函式會自動向包裝器新增 ``__wrapped__`` 屬性,"
"該包裝器參照被包裝的函式。"

#: ../../library/functools.rst:657
msgid ""
Expand Down

0 comments on commit ff862d0

Please sign in to comment.