@@ -530,6 +530,8 @@ msgid ""
530530"Use of :meth:`~importlib.abc.MetaPathFinder.find_module` by the import "
531531"system now raises :exc:`ImportWarning`."
532532msgstr ""
533+ "导入系统使用 :meth:`~importlib.abc.MetaPathFinder.find_module` 现在将会引发 "
534+ ":exc:`ImportWarning`。"
533535
534536#: ../../reference/import.rst:338
535537msgid "Loading"
@@ -853,13 +855,18 @@ msgid ""
853855" string for top-level modules, or for submodules, to the parent package's "
854856"name. See :pep:`366` for further details."
855857msgstr ""
858+ "模块的 ``__package__`` 属性必须设定。 其取值必须为一个字符串,但可以与 ``__name__`` 取相同的值。 当模块是包时,其 "
859+ "``__package__`` 值应该设为其 ``__name__`` 值。 当模块不是包时,对于最高层级模块 ``__package__`` "
860+ "应该设为空字符串,对于子模块则应该设为其父包名。 更多详情可参阅 :pep:`366`。"
856861
857862#: ../../reference/import.rst:565
858863msgid ""
859864"This attribute is used instead of ``__name__`` to calculate explicit "
860865"relative imports for main modules, as defined in :pep:`366`. It is expected "
861866"to have the same value as ``__spec__.parent``."
862867msgstr ""
868+ "该属性取代 ``__name__`` 被用来为主模块计算显式相对导入,相关定义见 :pep:`366`。 预期它与 "
869+ "``__spec__.parent`` 具有相同的值。"
863870
864871#: ../../reference/import.rst:569
865872msgid ""
@@ -883,7 +890,7 @@ msgstr ""
883890msgid ""
884891"When ``__package__`` is not defined, ``__spec__.parent`` is used as a "
885892"fallback."
886- msgstr ""
893+ msgstr "当 ``__package__`` 未定义时, ``__spec__.parent`` 会被用作回退项。 "
887894
888895#: ../../reference/import.rst:586
889896msgid ""
@@ -1049,6 +1056,8 @@ msgid ""
10491056"been deprecated and the module spec is now used by the import machinery to "
10501057"generate a module repr."
10511058msgstr ""
1059+ ":meth:`loader.module_repr() <importlib.abc.Loader.module_repr>` "
1060+ "已弃用,导入机制现在使用模块规格说明来生成模块 repr。"
10521061
10531062#: ../../reference/import.rst:684
10541063msgid ""
@@ -1057,6 +1066,8 @@ msgid ""
10571066"method, if defined, before trying either approach described above. However,"
10581067" the method is deprecated."
10591068msgstr ""
1069+ "为了向后兼容 Python 3.3,如果加载器定义了 :meth:`~importlib.abc.Loader.module_repr` "
1070+ "方法,则会在尝试上述两种方式之前先调用该方法来生成模块 repr。 但请注意此方法已弃用。"
10601071
10611072#: ../../reference/import.rst:691
10621073msgid ""
@@ -1065,6 +1076,9 @@ msgid ""
10651076"``__file__``. Use of :meth:`~importlib.abc.Loader.module_repr` is slated to "
10661077"stop in Python 3.12."
10671078msgstr ""
1079+ "对 :meth:`~importlib.abc.Loader.module_repr` 的调用现在会在尝试使用模块的 ``__spec__`` "
1080+ "属性之后但在回退至 ``__file__`` 之前发生。 :meth:`~importlib.abc.Loader.module_repr` "
1081+ "的使用预定会在 Python 3.12 中停止。"
10681082
10691083#: ../../reference/import.rst:699
10701084msgid "Cached bytecode invalidation"
@@ -1277,6 +1291,13 @@ msgid ""
12771291"forcing the path based finder to perform the path entry search again "
12781292"[#fnpic]_."
12791293msgstr ""
1294+ "基于路径的查找器会迭代搜索路径中的每个条目,并且每次都查找与路径条目对应的 :term:`path entry finder` "
1295+ "(:class:`~importlib.abc.PathEntryFinder`)。 因为这种操作可能很耗费资源 (例如搜索会有 ``stat()`` "
1296+ "调用的开销),基于路径的查找器会维持一个缓存来将路径条目映射到路径条目查找器。 这个缓存存放在 "
1297+ ":data:`sys.path_importer_cache` (尽管如此命名,但这个缓存实际存放的是查找器对象而非仅限于 "
1298+ ":term:`importer` 对象)。 通过这种方式,对特定 :term:`path entry` 位置的 :term:`path entry "
1299+ "finder` 的高耗费搜索中需要进行一次。 用户代码可以自由地从 :data:`sys.path_importer_cache` "
1300+ "移除缓存条目,以强制基于路径的查找器再次执行路径条目搜索 [#fnpic]_。"
12801301
12811302#: ../../reference/import.rst:828
12821303msgid ""
@@ -1371,6 +1392,8 @@ msgid ""
13711392":term:`portion`, the path entry finder sets \" submodule_search_locations\" "
13721393"to a list containing the portion."
13731394msgstr ""
1395+ "为了向导入机制提示该规格说明代表一个命名空间 :term:`portion`,路径条目查找器会将 "
1396+ "\" submodule_search_locations\" 设为一个包含该部分的列表。"
13741397
13751398#: ../../reference/import.rst:879
13761399msgid ""
@@ -1379,6 +1402,10 @@ msgid ""
13791402":meth:`~importlib.abc.PathEntryFinder.find_module`, both of which are now "
13801403"deprecated, but will be used if ``find_spec()`` is not defined."
13811404msgstr ""
1405+ ":meth:`~importlib.abc.PathEntryFinder.find_spec` 替代了 "
1406+ ":meth:`~importlib.abc.PathEntryFinder.find_loader` 和 "
1407+ ":meth:`~importlib.abc.PathEntryFinder.find_module`,后两者现在都已弃用,但会在 "
1408+ "``find_spec()`` 未定义时被使用。"
13821409
13831410#: ../../reference/import.rst:885
13841411msgid ""
@@ -1397,6 +1424,8 @@ msgid ""
13971424"returns a 2-tuple where the first item is the loader and the second item is "
13981425"a namespace :term:`portion`."
13991426msgstr ""
1427+ ":meth:`~importlib.abc.PathEntryFinder.find_loader` 接受一个参数,即要导入模块的完整限定名称。 "
1428+ "``find_loader()`` 返回一个 2 元组,其中第一项是加载器而第二项是命名空间 :term:`portion`。"
14001429
14011430#: ../../reference/import.rst:895
14021431msgid ""
@@ -1428,6 +1457,8 @@ msgid ""
14281457":meth:`~importlib.abc.PathEntryFinder.find_loader` by the import system will"
14291458" raise :exc:`ImportWarning`."
14301459msgstr ""
1460+ "导入系统调用 :meth:`~importlib.abc.PathEntryFinder.find_module` 和 "
1461+ ":meth:`~importlib.abc.PathEntryFinder.find_loader` 将引发 :exc:`ImportWarning`。"
14311462
14321463#: ../../reference/import.rst:915
14331464msgid "Replacing the standard import system"
@@ -1612,6 +1643,8 @@ msgid ""
16121643"Python 3.3. :pep:`420` also introduced the :meth:`find_loader` protocol as "
16131644"an alternative to :meth:`find_module`."
16141645msgstr ""
1646+ ":pep:`420` 为 Python 3.3 引入了 :term:`命名空间包 <namespace package>`。 :pep:`420` "
1647+ "还引入了 :meth:`find_loader` 协议作为 :meth:`find_module` 的替代。"
16151648
16161649#: ../../reference/import.rst:1037
16171650msgid ""
@@ -1670,6 +1703,8 @@ msgid ""
16701703"recommended that code be changed to use ``None`` instead. See "
16711704":ref:`portingpythoncode` for more details."
16721705msgstr ""
1706+ "在遗留代码中,有可能在 :data:`sys.path_importer_cache` 中找到 :class:`imp.NullImporter` "
1707+ "的实例。 建议将这些代码修改为使用 ``None`` 代替。 详情参见 :ref:`portingpythoncode`。"
16731708
16741709#: ../../reference/import.rst:8
16751710msgid "import machinery"
0 commit comments