]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-98040: Fix importbench: use types.ModuleType() (#105743)
authorVictor Stinner <vstinner@python.org>
Tue, 13 Jun 2023 22:32:12 +0000 (00:32 +0200)
committerGitHub <noreply@github.com>
Tue, 13 Jun 2023 22:32:12 +0000 (00:32 +0200)
Replace removed imp.new_module(name) with types.ModuleType(name).

Doc/whatsnew/3.12.rst
Tools/importbench/importbench.py

index bfbc6c7a35c6ffea3dc9ec184275ed4be6973080..1e063ed7d2263d2693418dfaa193d151c8a8e43c 100644 (file)
@@ -1369,6 +1369,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):