8000 gh-104212: Explain how to port imp code to importlib · python/cpython@fab77c8 · GitHub
[go: up one dir, main page]

Skip to content

Commit fab77c8

Browse files
committed
gh-104212: Explain how to port imp code to importlib
Explain in What's New in Python 3.12 how to port existing code using the removed imp to the importlib module.
1 parent ab3823a commit fab77c8

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

Doc/whatsnew/3.12.rst

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1369,7 +1369,38 @@ Removed
13691369
* The :mod:`!imp` module has been removed. (Contributed by Barry Warsaw in
13701370
:gh:`98040`.)
13711371

1372-
* Replace ``imp.new_module(name)`` with ``types.ModuleType(name)``.
1372+
* Replace removed :mod:`!imp` functions with :mod:`importlib` functions:
1373+
1374+
================================= =======================================
1375+
imp importlib
1376+
================================= =======================================
1377+
``imp.NullImporter`` Insert ``None`` into ``sys.path_importer_cache``
1378+
``imp.cache_from_source()`` :func:`importlib.util.cache_from_source`
1379+
``imp.find_module()`` :func:`importlib.util.find_spec`
1380+
``imp.get_magic()`` :attr:`importlib.util.MAGIC_NUMBER`
1381+
``imp.get_suffixes()`` :attr:`importlib.machinery.SOURCE_SUFFIXES`, :attr:`importlib.machinery.EXTENSION_SUFFIXES`, and :attr:`importlib.machinery.BYTECODE_SUFFIXES`
1382+
``imp.get_tag()`` :attr:`sys.implementation.cache_tag`
1383+
``imp.load_module()`` :func:`importlib.import_module`
1384+
``imp.new_module(name)`` ``types.ModuleType(name)``.
1385+
``imp.reload()`` :func:`importlib.reload`
1386+
``imp.source_from_cache()`` :func:`importlib.util.source_from_cache`
1387+
================================= =======================================
1388+
1389+
* Removed :mod:`!imp` functions and attributes with no replacements:
1390+
1391+
* undocumented functions:
1392+
1393+
* ``imp.init_builtin()``
1394+
* ``imp.load_compiled()``
1395+
* ``imp.load_dynamic()``
1396+
* ``imp.load_package()``
1397+
* ``imp.load_source()``
1398+
1399+
* ``imp.lock_held()``, ``imp.acquire_lock()``, ``imp.release_lock()``:
1400+
the locking scheme has changed in Python 3.3 to per-module locks.
1401+
* :func:`find_module` constants: ``SEARCH_ERROR``, ``PY_SOURCE``,
1402+
``PY_COMPILED``, ``C_EXTENSION``, ``PY_RESOURCE``, ``PKG_DIRECTORY``,
1403+
``C_BUILTIN``, ``PY_FROZEN``, ``PY_CODERESOURCE``, ``IMP_HOOK``.
13731404

13741405
* Removed the ``suspicious`` rule from the documentation Makefile, and
13751406
removed ``Doc/tools/rstlint.py``, both in favor of `sphinx-lint

0 commit comments

Comments
 (0)
0