@@ -11,7 +11,7 @@ msgid ""
1111msgstr ""
1212"Project-Id-Version : Python 3.12\n "
1313"Report-Msgid-Bugs-To : \n "
14- "POT-Creation-Date : 2025-01-24 14:52+0000\n "
14+ "POT-Creation-Date : 2025-02-07 14:52+0000\n "
1515"PO-Revision-Date : 2024-05-11 00:32+0000\n "
1616"
Last-Translator :
Rafael Fontenelle <[email protected] >, 2025\n "
1717"Language-Team : Chinese (China) (https://app.transifex.com/python-doc/teams/5390/zh_CN/)\n "
@@ -492,6 +492,8 @@ msgid ""
492492":meth:`~object.__set_name__` so that the field names would be recorded. "
493493"Here we call :func:`vars` to look up the descriptor without triggering it:"
494494msgstr ""
495+ "交互式会话显示 :class:`!Person` 类调用了 :meth:`~object.__set_name__` 以使字段名称可被记录。 "
496+ "在这里我们调用 :func:`vars` 来查找描述器而不触发它:"
495497
496498#: ../../howto/descriptor.rst:260
497499msgid ""
@@ -551,6 +553,8 @@ msgid ""
551553":meth:`~object.__get__`, :meth:`~object.__set__`, or "
552554":meth:`~object.__delete__`."
553555msgstr ""
556+ ":term:`descriptor` 是指任何定义了 :meth:`~object.__get__`, :meth:`~object.__set__` "
557+ "或 :meth:`~object.__delete__` 的对象。"
554558
555559#: ../../howto/descriptor.rst:300
556560msgid ""
@@ -559,6 +563,8 @@ msgid ""
559563" where it was created or the name of class variable it was assigned to. "
560564"(This method, if present, is called even if the class is not a descriptor.)"
561565msgstr ""
566+ "作为可选项,描述器可以有 :meth:`~object.__set_name__` 方法。 "
567+ "这仅会被用于当描述器需要知道创建它的类或它被分配的类变量名称等场合。 (此方法如果存在,那么即使所在类并不是一个描述器仍会被调用。)"
562568
563569#: ../../howto/descriptor.rst:305
564570msgid ""
@@ -628,6 +634,7 @@ msgid ""
628634"This :class:`!Validator` class is both an :term:`abstract base class` and a "
629635"managed attribute descriptor:"
630636msgstr ""
637+ "这个 :class:`!Validator` 类既是一个 :term:`abstract base class` 也是一个被管理的属性描述器:"
631638
632639#: ../../howto/descriptor.rst:343
633640msgid ""
@@ -672,6 +679,7 @@ msgid ""
672679"Custom validators need to inherit from :class:`!Validator` and must supply a"
673680" :meth:`!validate` method to test various restrictions as needed."
674681msgstr ""
682+ "自定义验证器必须继承自 :class:`!Validator` 并且必须提供 :meth:`!validate` 方法以根据需要测试各种约束。"
675683
676684#: ../../howto/descriptor.rst:368
677685msgid "Custom validators"
@@ -904,6 +912,9 @@ msgid ""
904912":meth:`~object.__set__`, and :meth:`~object.__delete__`. If any of those "
905913"methods are defined for an attribute, it is said to be a :term:`descriptor`."
906914msgstr ""
915+ "一般而言,描述器是具有描述器协议中的方法之一的属性值。 这些方法是 :meth:`~object.__get__`, "
916+ ":meth:`~object.__set__` 和 :meth:`~object.__delete__`。 "
917+ "如果为某个属性定义了这些方法中的任何一个,它就被称为 :term:`descriptor`。"
907918
908919#: ../../howto/descriptor.rst:505
909920msgid ""
@@ -962,6 +973,8 @@ msgid ""
962973":meth:`~object.__get__` are called non-data descriptors (they are often used"
963974" for methods but other uses are possible)."
964975msgstr ""
976+ "如果一个对象定义了 :meth:`~object.__set__` 或 :meth:`~object.__delete__`,它将被视为数据描述器。 "
977+ "仅定义了 :meth:`~object.__get__` 的描述器称为非数据描述器(它们经常被用于方法但也可以有其他用途。"
965978
966979#: ../../howto/descriptor.rst:539
967980msgid ""
@@ -1723,6 +1736,11 @@ msgid ""
17231736">>> d.f.__self__\n"
17241737"<__main__.D object at 0x00B18C90>"
17251738msgstr ""
1739+ ">>> d.f.__func__\n"
1740+ "<function D.f at 0x00C45070>\n"
1741+ "\n"
1742+ ">>> d.f.__self__\n"
1743+ "<__main__.D object at 0x00B18C90>"
17261744
17271745#: ../../howto/descriptor.rst:1245
17281746msgid ""
@@ -1881,6 +1899,20 @@ msgid ""
18811899" def __call__(self, *args, **kwds):\n"
18821900" return self.f(*args, **kwds)"
18831901msgstr ""
1902+ "import functools\n"
1903+ "\n"
1904+ "class StaticMethod:\n"
1905+ " \" Emulate PyStaticMethod_Type() in Objects/funcobject.c\" \n"
1906+ "\n"
1907+ " def __init__(self, f):\n"
1908+ " self.f = f\n"
1909+ " functools.update_wrapper(self, f)\n"
1910+ "\n"
1911+ " def __get__(self, obj, objtype=None):\n"
1912+ " return self.f\n"
1913+ "\n"
1914+ " def __call__(self, *args, **kwds):\n"
1915+ " return self.f(*args, **kwds)"
18841916
18851917#: ../../howto/descriptor.rst:1332
18861918msgid ""
@@ -1913,6 +1945,10 @@ msgid ""
19131945" def f(cls, x):\n"
19141946" return cls.__name__, x"
19151947msgstr ""
1948+ "class F:\n"
1949+ " @classmethod\n"
1950+ " def f(cls, x):\n"
1951+ " return cls.__name__, x"
19161952
19171953#: ../../howto/descriptor.rst:1414
19181954msgid ""
@@ -1921,6 +1957,10 @@ msgid ""
19211957">>> F().f(3)\n"
19221958"('F', 3)"
19231959msgstr ""
1960+ ">>> F.f(3)\n"
1961+ "('F', 3)\n"
1962+ ">>> F().f(3)\n"
1963+ "('F', 3)"
19241964
19251965#: ../../howto/descriptor.rst:1421
19261966msgid ""
@@ -1944,6 +1984,14 @@ msgid ""
19441984" d[key] = value\n"
19451985" return d"
19461986msgstr ""
1987+ "class Dict(dict):\n"
1988+ " @classmethod\n"
1989+ " def fromkeys(cls, iterable, value=None):\n"
1990+ " \" Emulate dict_fromkeys() in Objects/dictobject.c\" \n"
1991+ " d = cls()\n"
1992+ " for key in iterable:\n"
1993+ " d[key] = value\n"
1994+ " return d"
19471995
19481996#: ../../howto/descriptor.rst:1438
19491997msgid "Now a new dictionary of unique keys can be constructed like this:"
@@ -1957,6 +2005,11 @@ msgid ""
19572005">>> d\n"
19582006"{'a': None, 'b': None, 'r': None, 'c': None, 'd': None}"
19592007msgstr ""
2008+ ">>> d = Dict.fromkeys('abracadabra')\n"
2009+ ">>> type(d) is Dict\n"
2010+ "True\n"
2011+ ">>> d\n"
2012+ "{'a': None, 'b': None, 'r': None, 'c': None, 'd': None}"
19602013
19612014#: ../../howto/descriptor.rst:1448
19622015msgid ""
@@ -2044,6 +2097,8 @@ msgid ""
20442097"class Vehicle:\n"
20452098" __slots__ = ('id_number', 'make', 'model')"
20462099msgstr ""
2100+ "class Vehicle:\n"
2101+ " __slots__ = ('id_number', 'make', 'model')"
20472102
20482103#: ../../howto/descriptor.rst:1567
20492104msgid ""
@@ -2083,6 +2138,21 @@ msgid ""
20832138" def name(self): # Read-only descriptor\n"
20842139" return self._name"
20852140msgstr ""
2141+ "class Immutable:\n"
2142+ "\n"
2143+ " __slots__ = ('_dept', '_name') # 替代实例字典\n"
2144+ "\n"
2145+ " def __init__(self, dept, name):\n"
2146+ " self._dept = dept # 保存到私有属性\n"
2147+ " self._name = name # 保存到私有属性\n"
2148+ "\n"
2149+ " @property # 只读描述器\n"
2150+ " def dept(self):\n"
2151+ " return self._dept\n"
2152+ "\n"
2153+ " @property\n"
2154+ " def name(self): # 只读描述器\n"
2155+ " return self._name"
20862156
20872157#: ../../howto/descriptor.rst:1596
20882158msgid ""
@@ -2098,6 +2168,17 @@ msgid ""
20982168" ...\n"
20992169"AttributeError: 'Immutable' object has no attribute 'location'"
21002170msgstr ""
2171+ ">>> mark = Immutable('Botany', 'Mark Watney')\n"
2172+ ">>> mark.dept\n"
2173+ "'Botany'\n"
2174+ ">>> mark.dept = 'Space Pirate'\n"
2175+ "Traceback (most recent call last):\n"
2176+ " ...\n"
2177+ "AttributeError: property 'dept' of 'Immutable' object has no setter\n"
2178+ ">>> mark.location = 'Mars'\n"
2179+ "Traceback (most recent call last):\n"
2180+ " ...\n"
2181+ "AttributeError: 'Immutable' object has no attribute 'location'"
21012182
21022183#: ../../howto/descriptor.rst:1610
21032184msgid ""
@@ -2135,6 +2216,15 @@ msgid ""
21352216" return 4 * sum((-1.0)**n / (2.0*n + 1.0)\n"
21362217" for n in reversed(range(100_000)))"
21372218msgstr ""
2219+ "from functools import cached_property\n"
2220+ "\n"
2221+ "class CP:\n"
2222+ " __slots__ = () # 去除实例字典\n"
2223+ "\n"
2224+ " @cached_property # 需要一个实例字典\n"
2225+ " def pi(self):\n"
2226+ " return 4 * sum((-1.0)**n / (2.0*n + 1.0)\n"
2227+ " for n in reversed(range(100_000)))"
21382228
21392229#: ../../howto/descriptor.rst:1633
21402230msgid ""
@@ -2143,6 +2233,10 @@ msgid ""
21432233" ...\n"
21442234"TypeError: No '__dict__' attribute on 'CP' instance to cache 'pi' property."
21452235msgstr ""
2236+ ">>> CP().pi\n"
2237+ "Traceback (most recent call last):\n"
2238+ " ...\n"
2239+ "TypeError: No '__dict__' attribute on 'CP' instance to cache 'pi' property."
21462240
21472241#: ../../howto/descriptor.rst:1640
21482242msgid ""
0 commit comments