[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 457a459c78)

Co-authored-by: Victor Stinner <vstinner@python.org>
This commit is contained in:
Miss Islington (bot) 2023-06-13 15:59:02 -07:00 committed by GitHub
parent 27426d8983
commit 51b533ec50
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 1 deletions

View 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>`_.

View 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):