]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-98040: Fix importbench: use types.ModuleType() (GH-105743) (#105754)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 13 Jun 2023 22:59:02 +0000 (15:59 -0700)
committerGitHub <noreply@github.com>
Tue, 13 Jun 2023 22:59:02 +0000 (22:59 +0000)
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@python.org>
Doc/whatsnew/3.12.rst
Tools/importbench/importbench.py

index fcfd034b03903b7e70f73955eea39b647b805ba0..4849f8c3e281f959b5326565e846e46b2fcc37c3 100644 (file)
@@ -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>`_.
index 619263b553c081519063b826ea500b9ac36d52a9..0c4b3bc73517c5a58cfd9c9430a285496d4f17ca 100644 (file)
@@ -15,6 +15,7 @@ import py_compile
 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):