@@ -20,7 +20,7 @@ msgstr ""
2020
2121#: ../../library/abc.rst:2
2222msgid ":mod:`abc` --- Abstract Base Classes"
23- msgstr ":mod:`abc` —— 抽象类 "
23+ msgstr ":mod:`abc` —— 抽象基类 "
2424
2525#: ../../library/abc.rst:11
2626msgid "**Source code:** :source:`Lib/abc.py`"
@@ -34,7 +34,7 @@ msgid ""
3434" :mod:`numbers` module regarding a type hierarchy for numbers based on "
3535"ABCs.)"
3636msgstr ""
37- "该模块提供了在 Python 中定义 :term:`抽象类 <abstract base class>`(ABC)的组件,在 :pep:`3119` "
37+ "该模块提供了在 Python 中定义 :term:`抽象基类 <abstract base class>`(ABC)的组件,在 :pep:`3119` "
3838"中已有概述。查看 PEP 文档了解为什么需要在 Python 增加这个模块。(也可查看 :pep:`3141` 以及 :mod:`numbers` "
3939"模块了解基于 ABC 的数字类型继承关系。)"
4040
@@ -46,25 +46,25 @@ msgid ""
4646"whether a class or instance provides a particular interface, for example, is"
4747" it hashable or a mapping."
4848msgstr ""
49- ":mod:`collections` 模块定义了一些由抽象类派生出来的具体类 ,当然这些类可以再次派生。另外 :mod:`collections.abc` "
50- " 子模块定义了一些抽象类 ,可以用来检查类或实例是否定义了指定的接口,例如是否可以哈希或是可以映射 。"
49+ ":mod:`collections` 模块定义了一些由 ABC 派生出来的具体类 ,当然这些类可以再次派生。另外 "
50+ ":mod:`collections.abc` 子模块定义了一些 ABC ,可以用来检查类或实例是否定义了指定的接口,例如是否可以散列或是可以映射 。"
5151
5252#: ../../library/abc.rst:27
5353msgid ""
5454"This module provides the metaclass :class:`ABCMeta` for defining ABCs and a "
5555"helper class :class:`ABC` to alternatively define ABCs through inheritance:"
5656msgstr ""
5757"该模块提供了一个元类 :class:`ABCMeta`,可以用来定义抽象类,另外还提供一个工具类 "
58- ":class:`ABC`,可以用它以继承的方式定义抽象类 。"
58+ ":class:`ABC`,可以用它以继承的方式定义抽象基类 。"
5959
6060#: ../../library/abc.rst:32
6161msgid ""
6262"A helper class that has :class:`ABCMeta` as its metaclass. With this class,"
6363" an abstract base class can be created by simply deriving from :class:`ABC` "
6464"avoiding sometimes confusing metaclass usage, for example::"
6565msgstr ""
66- "一个使用 :class:`ABCMeta` 作为元类的工具类。抽象类可以通过简单地从 :class:`ABC` "
67- "派生来创建,这就避免了在某些情况下会令人混淆的元类使用 ,例如:"
66+ "一个使用 :class:`ABCMeta` 作为元类的工具类。抽象基类可以通过从 :class:`ABC` "
67+ "派生来简单地创建,这就避免了在某些情况下会令人混淆的元类用法 ,例如:"
6868
6969#: ../../library/abc.rst:41
7070msgid ""
@@ -75,11 +75,12 @@ msgid ""
7575"and using :class:`ABCMeta` directly, for example::"
7676msgstr ""
7777"注意 :class:`ABC` 的类型仍然是 :class:`ABCMeta`,因此继承 :class:`ABC` "
78- "仍然需要关注元类使用中的注意事项,比如多重继承可能会导致元类冲突。当然你也可以直接使用 :class:`ABCMeta` 作为元类来定义抽象类,例如:"
78+ "仍然需要关注元类使用中的注意事项,比如可能会导致元类冲突的多重继承。当然你也可以直接使用 :class:`ABCMeta` "
79+ "作为元类来定义抽象基类,例如:"
7980
8081#: ../../library/abc.rst:57
8182msgid "Metaclass for defining Abstract Base Classes (ABCs)."
82- msgstr "定义抽象类 (ABC)时使用的元类 。"
83+ msgstr "用于定义抽象基类 (ABC)的元类 。"
8384
8485#: ../../library/abc.rst:59
8586msgid ""
@@ -92,34 +93,37 @@ msgid ""
9293"will method implementations defined by the registering ABC be callable (not "
9394"even via :func:`super`). [#]_"
9495msgstr ""
96+ "使用该元类以创建抽象基类。抽象基类可以像 mix-in 类一样直接被子类继承。你也可以将不相关的具体类(包括内建类)和抽象基类注册为“抽象子类” —— "
97+ "这些类以及它们的子类会被内建函数 :func:`issubclass` 识别为对应的抽象基类的子类,但是该抽象基类不会出现在其 MRO(Method "
98+ "Resolution Order,方法解析顺序)中,抽象基类中实现的方法也不可调用(即使通过 :func:`super` 调用也不行)。[#]_"
9599
96100#: ../../library/abc.rst:68
97101msgid ""
98102"Classes created with a metaclass of :class:`ABCMeta` have the following "
99103"method:"
100- msgstr ""
104+ msgstr "使用 :class:`ABCMeta` 作为元类创建的类含有如下方法: "
101105
102106#: ../../library/abc.rst:72
103107msgid "Register *subclass* as a \" virtual subclass\" of this ABC. For example::"
104- msgstr ""
108+ msgstr "将“子类”注册为该抽象基类的“抽象子类”,例如: "
105109
106110#: ../../library/abc.rst:85
107111msgid "Returns the registered subclass, to allow usage as a class decorator."
108- msgstr ""
112+ msgstr "返回注册的子类,使其能够作为类装饰器。 "
109113
110114#: ../../library/abc.rst:88
111115msgid ""
112116"To detect calls to :meth:`register`, you can use the :func:`get_cache_token`"
113117" function."
114- msgstr ""
118+ msgstr "你可以使用 :func:`get_cache_token` 函数来检测对 :meth:`register` 的调用。 "
115119
116120#: ../../library/abc.rst:92
117121msgid "You can also override this method in an abstract base class:"
118122msgstr ""
119123
120124#: ../../library/abc.rst:96
121125msgid "(Must be defined as a class method.)"
122- msgstr ""
126+ msgstr "(必须定义为类方法。) "
123127
124128#: ../../library/abc.rst:98
125129msgid ""
@@ -129,6 +133,9 @@ msgid ""
129133" of the ABC. (This class method is called from the "
130134":meth:`__subclasscheck__` method of the ABC.)"
131135msgstr ""
136+ "检查 *subclass* 是否是该抽象基类的子类。也就是说对于那些你希望定义为该抽象基类的子类的类,你不用对每个类都调用 "
137+ ":meth:`register` 方法了,而是可以直接自定义 ``issubclass`` 的行为。(这个类方法是在抽象基类的 "
138+ ":meth:`__subclasscheck__` 方法中调用的。)"
132139
133140#: ../../library/abc.rst:104
134141msgid ""
@@ -138,11 +145,14 @@ msgid ""
138145" even if it would normally be one. If it returns ``NotImplemented``, the "
139146"subclass check is continued with the usual mechanism."
140147msgstr ""
148+ "该方法必须返回 ``True``, ``False`` 或是 ``NotImplemented``。如果返回 ``True``,*subclass* "
149+ "就会被认为是这个抽象基类的子类。如果返回 ``False``,无论正常情况是否应该认为是其子类,统一视为不是。如果返回 "
150+ "``NotImplemented``,子类检查会按照正常机制继续执行。"
141151
142152#: ../../library/abc.rst:114
143153msgid ""
144154"For a demonstration of these concepts, look at this example ABC definition::"
145- msgstr ""
155+ msgstr "为了对这些概念做一演示,请看以下定义 ABC 的示例: "
146156
147157#: ../../library/abc.rst:143
148158msgid ""
0 commit comments