From bc20c9569eee88d3fd6f8fc9bdd9f9e1a5f8493a Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Wed, 14 Jun 2023 00:32:12 +0200 Subject: [PATCH] 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 --- Doc/whatsnew/3.12.rst | 2 ++ Tools/importbench/importbench.py | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst index fcfd034b03903b..4849f8c3e281f9 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 `_. diff --git a/Tools/importbench/importbench.py b/Tools/importbench/importbench.py index 619263b553c081..0c4b3bc73517c5 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 = '' - module = imp.new_module(name) + module = types.ModuleType(name) module.__file__ = '' module.__package__ = '' with util.uncache(name):