8000 Translate faq/design.html#how-do-you-specify-and-enforce-an-interface… · python/python-docs-zh-tw@44ae53a · GitHub
[go: up one dir, main page]

Skip to content

Commit 44ae53a

Browse files
committed
Translate faq/design.html#how-do-you-specify-and-enforce-an-interface-spec-in-python
1 parent 0c984c6 commit 44ae53a

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

faq/design.po

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -966,7 +966,7 @@ msgstr ""
966966

967967
#: ../../faq/design.rst:556
968968
msgid "How do you specify and enforce an interface spec in Python?"
969-
msgstr ""
969+
msgstr "如何在 Python 中指定和強制使用一個介面規範 (interface spec)?"
970970

971971
#: ../../faq/design.rst:558
972972
msgid ""
@@ -975,6 +975,8 @@ msgid ""
975975
"module. Many feel that compile-time enforcement of interface specifications "
976976
"helps in the construction of large programs."
977977
msgstr ""
978+
"像是 C++ 和 Java 等語言提供了模組的介面規範,他描述了該模組的方法和函式的原"
979+
"型。很多人認為這種在編譯時強制執行的介面規範在建構大型程式時十分有幫助。"
978980

979981
#: ../../faq/design.rst:563
980982
msgid ""
@@ -985,12 +987,18 @@ msgid ""
985987
"`~collections.abc.Iterable`, :class:`~collections.abc.Container`, and :class:"
986988
"`~collections.abc.MutableMapping`."
987989
msgstr ""
990+
"Python 2.6 加入了 :mod:`abc` 模組,讓你可以定義抽象基底類別 (Abstract Base "
991+
"Classes, ABCs)。你可以使用 :func:`isinstance` 和 :func:`issubclass` 來確認一"
992+
"個實體 (instance) 或是類別是否實作了某個抽象基底類別。而 :mod:`collections."
993+
"abc` 模組定義了一系列好用的抽象基底類別,像是 :class:`~collections.abc."
994+
"Iterable`、:class:`~collections.abc.Container` 和 :class:`~collections.abc."
995+
"MutableMapping`。"
988996

989997
#: ../../faq/design.rst:570
990998
msgid ""
991999
"For Python, many of the advantages of interface specifications can be "
9921000
"obtained by an appropriate test discipline for components."
993-
msgstr ""
1001+
msgstr "對 Python 來說,很多介面規範的優點可以用對元件適當的測試規則來達到。"
9941002

9951003
#: ../../faq/design.rst:573
9961004
msgid ""
@@ -1003,6 +1011,11 @@ msgid ""
10031011
"be used to construct exhaustive test suites that exercise every line of code "
10041012
"in a module."
10051013
msgstr ""
1014+
"一個針對模組的好測試套件提供了回歸測試 (regression testing),並作為模組介面規"
1015+
"範和一組範例。許多 Python 模組可以直接當成腳本執行,並提供簡單的「自我測"
1016+
"試」。即便模組使用了複雜的外部介面,他依然可以用外部介面的簡單的「樁」(stub) "
1017+
"模擬來獨立測試。:mod:`doctest` 和 :mod:`unittest` 模組或第三方的測試框架可以"
1018+
"用來建構詳盡徹底的測試套件來測試模組裡的每一行程式碼。"
10061019

10071020
#: ../../faq/design.rst:581
10081021
msgid ""
@@ -1014,6 +1027,11 @@ msgid ""
10141027
"test that your :meth:`append` implementation will actually do this "
10151028
"correctly, but it's trivial to check this property in a test suite."
10161029
msgstr ""
1030+
"就像介面規範一樣,一個適當的測試規則在建造大型又複雜的 Python 應用程式時可以"
1031+
"幫上忙。事實上,他可能可以有更好的表現,因為介面規範無法測試程式的特定屬性。"
1032+
"舉例來說,:meth:`append` 方法應該要在某個內部的串列最後面加上新的元素,而介面"
1033+
"規範沒辦法測試你的 :meth:`append` 是不是真的有正確的實作,但這在測試套件裡事"
1034+
"件很簡單的事。"
10171035

10181036
#: ../../faq/design.rst:589
10191037
msgid ""
@@ -1023,6 +1041,9 @@ msgid ""
10231041
"write any of the actual code. Of course Python allows you to be sloppy and "
10241042
"not write test cases at all."
10251043
msgstr ""
1044+
"撰寫測試套件相當有幫助,而你會像要把程式碼設計成好測試的樣子。測試驅動開發 "
1045+
"(test-driven development) 是一個越來越受歡迎的設計方法,他要求先完成部分的測"
1046+
"試套件,再去撰寫真的要用的程式碼。當然 Python 也允許你草率地不寫任何測試。"
10261047

10271048
#: ../../faq/design.rst:597
10281049
msgid "Why is there no goto?"

0 commit comments

Comments
 (0)
0