@@ -11,7 +11,7 @@ msgid ""
11
11
msgstr ""
12
12
"Project-Id-Version : Python 3.12\n "
13
13
"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 "
15
15
"PO-Revision-Date : 2024-05-11 00:32+0000\n "
16
16
"
Last-Translator :
Rafael Fontenelle <[email protected] >, 2025\n "
17
17
"Language-Team : Chinese (China) (https://app.transifex.com/python-doc/teams/5390/zh_CN/)\n "
@@ -492,6 +492,8 @@ msgid ""
492
492
":meth:`~object.__set_name__` so that the field names would be recorded. "
493
493
"Here we call :func:`vars` to look up the descriptor without triggering it:"
494
494
msgstr ""
495
+ "交互式会话显示 :class:`!Person` 类调用了 :meth:`~object.__set_name__` 以使字段名称可被记录。 "
496
+ "在这里我们调用 :func:`vars` 来查找描述器而不触发它:"
495
497
496
498
#: ../../howto/descriptor.rst:260
497
499
msgid ""
@@ -551,6 +553,8 @@ msgid ""
551
553
":meth:`~object.__get__`, :meth:`~object.__set__`, or "
552
554
":meth:`~object.__delete__`."
553
555
msgstr ""
556
+ ":term:`descriptor` 是指任何定义了 :meth:`~object.__get__`, :meth:`~object.__set__` "
557
+ "或 :meth:`~object.__delete__` 的对象。"
554
558
555
559
#: ../../howto/descriptor.rst:300
556
560
msgid ""
@@ -559,6 +563,8 @@ msgid ""
559
563
" where it was created or the name of class variable it was assigned to. "
560
564
"(This method, if present, is called even if the class is not a descriptor.)"
561
565
msgstr ""
566
+ "作为可选项,描述器可以有 :meth:`~object.__set_name__` 方法。 "
567
+ "这仅会被用于当描述器需要知道创建它的类或它被分配的类变量名称等场合。 (此方法如果存在,那么即使所在类并不是一个描述器仍会被调用。)"
562
568
563
569
#: ../../howto/descriptor.rst:305
564
570
msgid ""
@@ -628,6 +634,7 @@ msgid ""
628
634
"This :class:`!Validator` class is both an :term:`abstract base class` and a "
629
635
"managed attribute descriptor:"
630
636
msgstr ""
637
+ "这个 :class:`!Validator` 类既是一个 :term:`abstract base class` 也是一个被管理的属性描述器:"
631
638
632
639
#: ../../howto/descriptor.rst:343
633
640
msgid ""
@@ -672,6 +679,7 @@ msgid ""
672
679
"Custom validators need to inherit from :class:`!Validator` and must supply a"
673
680
" :meth:`!validate` method to test various restrictions as needed."
674
681
msgstr ""
682
+ "自定义验证器必须继承自 :class:`!Validator` 并且必须提供 :meth:`!validate` 方法以根据需要测试各种约束。"
675
683
676
684
#: ../../howto/descriptor.rst:368
677
685
msgid "Custom validators"
@@ -904,6 +912,9 @@ msgid ""
904
912
":meth:`~object.__set__`, and :meth:`~object.__delete__`. If any of those "
905
913
"methods are defined for an attribute, it is said to be a :term:`descriptor`."
906
914
msgstr ""
915
+ "一般而言,描述器是具有描述器协议中的方法之一的属性值。 这些方法是 :meth:`~object.__get__`, "
916
+ ":meth:`~object.__set__` 和 :meth:`~object.__delete__`。 "
917
+ "如果为某个属性定义了这些方法中的任何一个,它就被称为 :term:`descriptor`。"
907
918
908
919
#: ../../howto/descriptor.rst:505
909
920
msgid ""
@@ -962,6 +973,8 @@ msgid ""
962
973
":meth:`~object.__get__` are called non-data descriptors (they are often used"
963
974
" for methods but other uses are possible)."
964
975
msgstr ""
976
+ "如果一个对象定义了 :meth:`~object.__set__` 或 :meth:`~object.__delete__`,它将被视为数据描述器。 "
977
+ "仅定义了 :meth:`~object.__get__` 的描述器称为非数据描述器(它们经常被用于方法但也可以有其他用途。"
965
978
966
979
#: ../../howto/descriptor.rst:539
967
980
msgid ""
@@ -1723,6 +1736,11 @@ msgid ""
1723
1736
">>> d.f.__self__\n"
1724
1737
"<__main__.D object at 0x00B18C90>"
1725
1738
msgstr ""
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>"
1726
1744
1727
1745
#: ../../howto/descriptor.rst:1245
1728
1746
msgid ""
@@ -1881,6 +1899,20 @@ msgid ""
1881
1899
" def __call__(self, *args, **kwds):\n"
1882
1900
" return self.f(*args, **kwds)"
1883
1901
msgstr ""
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)"
1884
1916
1885
1917
#: ../../howto/descriptor.rst:1332
1886
1918
msgid ""
@@ -1913,6 +1945,10 @@ msgid ""
1913
1945
" def f(cls, x):\n"
1914
1946
" return cls.__name__, x"
1915
1947
msgstr ""
1948
+ "class F:\n"
1949
+ " @classmethod\n"
1950
+ " def f(cls, x):\n"
1951
+ " return cls.__name__, x"
1916
1952
1917
1953
#: ../../howto/descriptor.rst:1414
1918
1954
msgid ""
@@ -1921,6 +1957,10 @@ msgid ""
1921
1957
">>> F().f(3)\n"
1922
1958
"('F', 3)"
1923
1959
msgstr ""
1960
+ ">>> F.f(3)\n"
1961
+ "('F', 3)\n"
1962
+ ">>> F().f(3)\n"
1963
+ "('F', 3)"
1924
1964
1925
1965
#: ../../howto/descriptor.rst:1421
1926
1966
msgid ""
@@ -1944,6 +1984,14 @@ msgid ""
1944
1984
" d[key] = value\n"
1945
1985
" return d"
1946
1986
msgstr ""
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"
1947
1995
1948
1996
#: ../../howto/descriptor.rst:1438
1949
1997
msgid "Now a new dictionary of unique keys can be constructed like this:"
@@ -1957,6 +2005,11 @@ msgid ""
1957
2005
">>> d\n"
1958
2006
"{'a': None, 'b': None, 'r': None, 'c': None, 'd': None}"
1959
2007
msgstr ""
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}"
1960
2013
1961
2014
#: ../../howto/descriptor.rst:1448
1962
2015
msgid ""
@@ -2044,6 +2097,8 @@ msgid ""
2044
2097
"class Vehicle:\n"
2045
2098
" __slots__ = ('id_number', 'make', 'model')"
2046
2099
msgstr ""
2100
+ "class Vehicle:\n"
2101
+ " __slots__ = ('id_number', 'make', 'model')"
2047
2102
2048
2103
#: ../../howto/descriptor.rst:1567
2049
2104
msgid ""
@@ -2083,6 +2138,21 @@ msgid ""
2083
2138
" def name(self): # Read-only descriptor\n"
2084
2139
" return self._name"
2085
2140
msgstr ""
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"
2086
2156
2087
2157
#: ../../howto/descriptor.rst:1596
2088
2158
msgid ""
@@ -2098,6 +2168,17 @@ msgid ""
2098
2168
" ...\n"
2099
2169
"AttributeError: 'Immutable' object has no attribute 'location'"
2100
2170
msgstr ""
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'"
2101
2182
2102
2183
#: ../../howto/descriptor.rst:1610
2103
2184
msgid ""
@@ -2135,6 +2216,15 @@ msgid ""
2135
2216
" return 4 * sum((-1.0)**n / (2.0*n + 1.0)\n"
2136
2217
" for n in reversed(range(100_000)))"
2137
2218
msgstr ""
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)))"
2138
2228
2139
2229
#: ../../howto/descriptor.rst:1633
2140
2230
msgid ""
@@ -2143,6 +2233,10 @@ msgid ""
2143
2233
" ...\n"
2144
2234
"TypeError: No '__dict__' attribute on 'CP' instance to cache 'pi' property."
2145
2235
msgstr ""
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."
2146
2240
2147
2241
#: ../../howto/descriptor.rst:1640
2148
2242
msgid ""
0 commit comments