[Python-checkins] [3.12] gh-98040: Fix importbench: use types.ModuleType() (GH-105743) (#105754)

vstinner webhook-mailer at python.org
Tue Jun 13 18:59:09 EDT 2023


https://github.com/python/cpython/commit/51b533ec5049593dc009383226f935cf5181484c
commit: 51b533ec5049593dc009383226f935cf5181484c
branch: 3.12
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: vstinner <vstinner at python.org>
date: 2023-06-13T22:59:02Z
summary:

[3.12] gh-98040: Fix importbench: use types.ModuleType() (GH-105743) (#105754)

gh-98040: Fix importbench: use types.ModuleType() (GH-105743)

Replace removed imp.new_module(name) with types.ModuleType(name).
(cherry picked from commit 457a459c7804950d4c27a243b176eb933ec87a06)

Co-authored-by: Victor Stinner <vstinner at python.org>

files:
M Doc/whatsnew/3.12.rst
M Tools/importbench/importbench.py

diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst
index fcfd034b03903..4849f8c3e281f 100644
--- a/Doc/whatsnew/3.12.rst
+++ b/Doc/whatsnew/3.12.rst
@@ -1368,6 +1368,8 @@ Removed
   * The :mod:`!imp` module has been removed.  (Contributed by Barry Warsaw in
     :gh:`98040`.)
 
+  * Replace ``imp.new_module(name)`` with ``types.ModuleType(name)``.
+
 * Removed the ``suspicious`` rule from the documentation Makefile, and
   removed ``Doc/tools/rstlint.py``, both in favor of `sphinx-lint
   <https://github.com/sphinx-contrib/sphinx-lint>`_.
diff --git a/Tools/importbench/importbench.py b/Tools/importbench/importbench.py
index 619263b553c08..0c4b3bc73517c 100644
--- a/Tools/importbench/importbench.py
+++ b/Tools/importbench/importbench.py
@@ -15,6 +15,7 @@
 import sys
 import tabnanny
 import timeit
+import types
 
 
 def bench(name, cleanup=lambda: None, *, seconds=1, repeat=3):
@@ -40,7 +41,7 @@ def bench(name, cleanup=lambda: None, *, seconds=1, repeat=3):
 def from_cache(seconds, repeat):
     """sys.modules"""
     name = '<benchmark import>'
-    module = imp.new_module(name)
+    module = types.ModuleType(name)
     module.__file__ = '<test>'
     module.__package__ = ''
     with util.uncache(name):



More information about the Python-checkins mailing list