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>
* 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>`_.
import sys
import tabnanny
import timeit
+import types
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):