26
26
# LeeWendao <LeeWendao@outlook.com>, 2023
27
27
# Alpha Du <alphanow@gmail.com>, 2024
28
28
# lqks, 2024
29
+ # Nyuan Zhang, 2025
29
30
# Freesand Leo <yuqinju@163.com>, 2025
30
31
#
31
32
#, fuzzy
@@ -1186,6 +1187,10 @@ msgid ""
1186
1187
" manually set on the module object after it has been created when using this"
1187
1188
" approach."
1188
1189
msgstr ""
1190
+ "要动态创建模块而非使用导入系统创建,建议使用 "
1191
+ ":func:`importlib.util.module_from_spec`,它会将各种由导入控制的属性设置为适当的值。也可以使用 "
1192
+ ":class:`types.ModuleType` "
1193
+ "构造器直接创建模块,但这种方法更容易出错,因为在使用这种方法时,必须在创建模块对象后手动设置其大部分属性。"
1189
1194
1190
1195
#: ../../reference/datamodel.rst:912
1191
1196
msgid ""
@@ -1195,6 +1200,8 @@ msgid ""
1195
1200
" Note that updating an attribute on :attr:`!__spec__` will not update the "
1196
1201
"corresponding attribute on the module itself:"
1197
1202
msgstr ""
1203
+ "对 :attr:`~module.__name__` 以外的用例,**强烈** 建议使用 :attr:`~module.__spec__` "
1204
+ "及其属性,而非此处列出的其他单独属性。请注意更新 :attr:`!__spec__` 上的属性时不会连带更新模块本身的同名属性。"
1198
1205
1199
1206
#: ../../reference/datamodel.rst:918
1200
1207
msgid ""
@@ -1257,6 +1264,8 @@ msgid ""
1257
1264
":attr:`module.__name__` if the module itself is a package). See :pep:`366` "
1258
1265
"for further details."
1259
1266
msgstr ""
1267
+ "如果一个模块是顶层模块(不是任何包的一部分),该属性应被设置为空字符串 ``''``。否则,它应被设置为模块所属包的名字(如果模块本身是一个包,它可以是"
1268
+ " :attr:`module.__name__` 的值)。详见 :pep:`366`。"
1260
1269
1261
1270
#: ../../reference/datamodel.rst:958
1262
1271
msgid ""
@@ -1266,6 +1275,9 @@ msgid ""
1266
1275
" use :func:`importlib.util.module_from_spec` instead to ensure the attribute"
1267
1276
" is set to a :class:`str`."
1268
1277
msgstr ""
1278
+ "在为主模块计算显式相对导入时,这个属性而非 :attr:`~module.__name__` 被使用。在使用 "
1279
+ ":class:`types.ModuleType` 构造器动态创建模块时会被默认设为 ``None``。要确保这个属性是 "
1280
+ ":class:`str`,请使用 :func:`importlib.util.module_from_spec`。"
1269
1281
1270
1282
#: ../../reference/datamodel.rst:964
1271
1283
msgid ""
@@ -1275,13 +1287,17 @@ msgid ""
1275
1287
"fallback if :attr:`!__spec__.parent` is not set, and this fallback path is "
1276
1288
"deprecated."
1277
1289
msgstr ""
1290
+ "**强烈** 建议使用 :attr:`module.__spec__.parent "
1291
+ "<importlib.machinery.ModuleSpec.parent>` 而非 :attr:`!module.__package__`。 "
1292
+ ":attr:`__package__` 现在仅作 :attr:`!__spec__.parent` 未被设置时的回退路径,且这条回退路径已被弃用。"
1278
1293
1279
1294
#: ../../reference/datamodel.rst:970 ../../reference/datamodel.rst:1011
1280
1295
msgid ""
1281
1296
"This attribute now defaults to ``None`` for modules created dynamically "
1282
1297
"using the :class:`types.ModuleType` constructor. Previously the attribute "
1283
1298
"was optional."
1284
1299
msgstr ""
1300
+ "对于使用 :class:`types.ModuleType` 构造器动态创建的模块,该属性现在默认为 ``None``。先前该属性是可选的。"
1285
1301
1286
1302
#: ../../reference/datamodel.rst:975
1287
1303
msgid ""
@@ -1290,37 +1306,44 @@ msgid ""
1290
1306
":attr:`__package__` is now only used as a fallback during import resolution "
1291
1307
"if :attr:`!__spec__.parent` is not defined."
1292
1308
msgstr ""
1309
+ ":attr:`!__package__` 的值应与 :attr:`__spec__.parent "
1310
+ "<importlib.machinery.ModuleSpec.parent>` 相同。:attr:`__package__` 现在仅作导入解析期间 "
1311
+ ":attr:`!__spec__.parent` 未被定义时的回退值。"
1293
1312
1294
1313
#: ../../reference/datamodel.rst:981
1295
1314
msgid ""
1296
1315
":exc:`ImportWarning` is raised if an import resolution falls back to "
1297
1316
":attr:`!__package__` instead of :attr:`__spec__.parent "
1298
1317
"<importlib.machinery.ModuleSpec.parent>`."
1299
1318
msgstr ""
1319
+ "如果导入解析回退到 :attr:`!__package__` 而非 :attr:`__spec__.parent "
1320
+ "<importlib.machinery.ModuleSpec.parent>`,会引发 :exc:`ImportWarning`。"
1300
1321
1301
1322
#: ../../reference/datamodel.rst:986
1302
1323
msgid ""
1303
1324
"Raise :exc:`DeprecationWarning` instead of :exc:`ImportWarning` when falling"
1304
1325
" back to :attr:`!__package__` during import resolution."
1305
1326
msgstr ""
1327
+ "在导入解析期间回退到 :attr:`!__package__` 时会引发 :exc:`DeprecationWarning` 而非 "
1328
+ ":exc:`ImportWarning`。"
1306
1329
1307
1330
#: ../../reference/datamodel.rst:990
1308
1331
msgid ""
1309
1332
":attr:`!__package__` will cease to be set or taken into consideration by the"
1310
1333
" import system or standard library."
1311
- msgstr ""
1334
+ msgstr ":attr:`!__package__` 将不再被设置或者被导入系统或标准库纳入考量。 "
1312
1335
1313
1336
#: ../../reference/datamodel.rst:996
1314
1337
msgid ""
1315
1338
"The :term:`loader` object that the import machinery used to load the module."
1316
- msgstr ""
1339
+ msgstr "导入系统用来加载模块的 :term:`loader` 对象。 "
1317
1340
1318
1341
#: ../../reference/datamodel.rst:998
1319
1342
msgid ""
1320
1343
"This attribute is mostly useful for introspection, but can be used for "
1321
1344
"additional loader-specific functionality, for example getting data "
1322
1345
"associated with a loader."
1323
- msgstr ""
1346
+ msgstr "该属性主要适用于内省,但也可用于额外的加载器专属功能,例如获取与加载器相关联的数据。 "
1324
1347
1325
1348
#: ../../reference/datamodel.rst:1002
1326
1349
msgid ""
0 commit comments