@@ -1328,6 +1328,8 @@ msgid ""
1328
1328
"place at the time of class creation. If descriptors are added to the class "
1329
1329
"afterwards, :meth:`~object.__set_name__` will need to be called manually."
1330
1330
msgstr ""
1331
+ "由于更新逻辑是在 :meth:`!type.__new__` 中,因此通知仅在类创建时发出。 之后如果将描述器添加到类中,则需要手动调用 "
1332
+ ":meth:`~object.__set_name__`。"
1331
1333
1332
1334
#: ../../howto/descriptor.rst:851
1333
1335
msgid "ORM example"
@@ -1383,6 +1385,8 @@ msgid ""
1383
1385
"<https://en.wikipedia.org/wiki/Database_model>`_ that describe the schema "
1384
1386
"for each table in a database:"
1385
1387
msgstr ""
1388
+ "我们可以使用 :class:`!Field` 类来定义描述了数据库中每张表的结构的 `模型 "
1389
+ "<https://en.wikipedia.org/wiki/Database_model>`_:"
1386
1390
1387
1391
#: ../../howto/descriptor.rst:880
1388
1392
msgid ""
@@ -1740,6 +1744,8 @@ msgid ""
1740
1744
" This means that functions are non-data descriptors that return bound "
1741
1745
"methods during dotted lookup from an instance. Here's how it works:"
1742
1746
msgstr ""
1747
+ "为支持方法的自动创建,函数会包括 :meth:`~object.__get__` 方法以便在属性访问期间绑定方法。 "
1748
+ "这意味着函数就是在通过实例进行点号查找期间返回所绑定方法的非数据描述器。 其运作方式是这样的:"
1743
1749
1744
1750
#: ../../howto/descriptor.rst:1194
1745
1751
msgid ""
@@ -1802,7 +1808,7 @@ msgid ""
1802
1808
"Accessing the function through the class dictionary does not invoke "
1803
1809
":meth:`~object.__get__`. Instead, it just returns the underlying function "
1804
1810
"object::"
1805
- msgstr ""
1811
+ msgstr "通过类字典访问函数不会唤起 :meth:`~object.__get__`。 相反,它只是返回下层的函数对象:: "
1806
1812
1807
1813
#: ../../howto/descriptor.rst:1236
1808
1814
msgid ""
@@ -1816,7 +1822,7 @@ msgstr ""
1816
1822
msgid ""
1817
1823
"Dotted access from a class calls :meth:`~object.__get__` which just returns "
1818
1824
"the underlying function unchanged::"
1819
- msgstr ""
1825
+ msgstr "通过类进行点号访问调用 :meth:`~object.__get__`,它将只原样返回下层的函数:: "
1820
1826
1821
1827
#: ../../howto/descriptor.rst:1242
1822
1828
msgid ""
@@ -1831,7 +1837,7 @@ msgid ""
1831
1837
"The interesting behavior occurs during dotted access from an instance. The "
1832
1838
"dotted lookup calls :meth:`~object.__get__` which returns a bound method "
1833
1839
"object::"
1834
- msgstr ""
1840
+ msgstr "有趣的行为发生在通过实例进行点号访问期间。 点号查找调用 :meth:`~object.__get__`,它将返回绑定的方法对象:: "
1835
1841
1836
1842
#: ../../howto/descriptor.rst:1248
1837
1843
msgid ""
@@ -1886,6 +1892,9 @@ msgid ""
1886
1892
"descriptor transforms an ``obj.f(*args)`` call into ``f(obj, *args)``. "
1887
1893
"Calling ``cls.f(*args)`` becomes ``f(*args)``."
1888
1894
msgstr ""
1895
+ "总结一下,函数具有 :meth:`~object.__get__` 方法以便在其作为属性被访问时可被转换为方法。 非数据描述器会将 "
1896
+ "``obj.f(*args)`` 调用转化为 ``f(obj, *args)``。 调用 ``cls.f(*args)`` 将变成 "
1897
+ "``f(*args)``。"
1889
1898
1890
1899
#: ../../howto/descriptor.rst:1276
1891
1900
msgid "This chart summarizes the binding and its two most useful variants:"
@@ -1963,6 +1972,9 @@ msgid ""
1963
1972
" particular dataset. It can be called either from an object or the class: "
1964
1973
"``s.erf(1.5) --> 0.9332`` or ``Sample.erf(1.5) --> 0.9332``."
1965
1974
msgstr ""
1975
+ "举例来说,一个统计软件包可能包括存放实验性数据的容器类。 该类提供了用于计算平均数、均值、中位数以及其他描述性的统计数据的方法。 "
1976
+ "不过,还可能存在在概念上相关但不依赖于这些数据的有用函数。 例如,``erf(x)`` 是在统计工作中的便捷转换例程但并不直接依赖于特定的数据集。 "
1977
+ "它可以通过对象或者类来调用: ``s.erf(1.5) --> 0.9332`` 或者 ``Sample.erf(1.5) --> 0.9332``。"
1966
1978
1967
1979
#: ../../howto/descriptor.rst:1311
1968
1980
msgid ""
@@ -2393,6 +2405,41 @@ msgid ""
2393
2405
" 'Emulate member_repr() in Objects/descrobject.c'\n"
2394
2406
" return f'<Member {self.name!r} of {self.clsname!r}>'"
2395
2407
msgstr ""
2408
+ "null = object()\n"
2409
+ "\n"
2410
+ "class Member:\n"
2411
+ "\n"
2412
+ " def __init__(self, name, clsname, offset):\n"
2413
+ " 'Emulate PyMemberDef in Include/structmember.h'\n"
2414
+ " # 另请参阅 Objects/descrobject.c 中的 descr_new()\n"
2415
+ " self.name = name\n"
2416
+ " self.clsname = clsname\n"
2417
+ " self.offset = offset\n"
2418
+ "\n"
2419
+ " def __get__(self, obj, objtype=None):\n"
2420
+ " 'Emulate member_get() in Objects/descrobject.c'\n"
2421
+ " # 另请参阅 Python/structmember.c 中的 PyMember_GetOne()\n"
2422
+ " if obj is None:\n"
2423
+ " return self\n"
2424
+ " value = obj._slotvalues[self.offset]\n"
2425
+ " if value is null:\n"
2426
+ " raise AttributeError(self.name)\n"
2427
+ " return value\n"
2428
+ "\n"
2429
+ " def __set__(self, obj, value):\n"
2430
+ " 'Emulate member_set() in Objects/descrobject.c'\n"
2431
+ " obj._slotvalues[self.offset] = value\n"
2432
+ "\n"
2433
+ " def __delete__(self, obj):\n"
2434
+ " 'Emulate member_delete() in Objects/descrobject.c'\n"
2435
+ " value = obj._slotvalues[self.offset]\n"
2436
+ " if value is null:\n"
2437
+ " raise AttributeError(self.name)\n"
2438
+ " obj._slotvalues[self.offset] = null\n"
2439
+ "\n"
2440
+ " def __repr__(self):\n"
2441
+ " 'Emulate member_repr() in Objects/descrobject.c'\n"
2442
+ " return f'<Member {self.name!r} of {self.clsname!r}>'"
2396
2443
2397
2444
#: ../../howto/descriptor.rst:1670
2398
2445
msgid ""
0 commit comments