Skip to content

Commit 457a459

Browse files
authored
gh-98040: Fix importbench: use types.ModuleType() (#105743)
Replace removed imp.new_module(name) with types.ModuleType(name).
1 parent 757b402 commit 457a459

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

Diff for: Doc/whatsnew/3.12.rst

+2
Original file line numberDiff line numberDiff line change
@@ -1369,6 +1369,8 @@ Removed
13691369
* The :mod:`!imp` module has been removed. (Contributed by Barry Warsaw in
13701370
:gh:`98040`.)
13711371

1372+
* Replace ``imp.new_module(name)`` with ``types.ModuleType(name)``.
1373+
13721374
* Removed the ``suspicious`` rule from the documentation Makefile, and
13731375
removed ``Doc/tools/rstlint.py``, both in favor of `sphinx-lint
13741376
<https://github.com/sphinx-contrib/sphinx-lint>`_.

Diff for: Tools/importbench/importbench.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import sys
1616
import tabnanny
1717
import timeit
18+
import types
1819

1920

2021
def bench(name, cleanup=lambda: None, *, seconds=1, repeat=3):
@@ -40,7 +41,7 @@ def bench(name, cleanup=lambda: None, *, seconds=1, repeat=3):
4041
def from_cache(seconds, repeat):
4142
"""sys.modules"""
4243
name = '<benchmark import>'
43-
module = imp.new_module(name)
44+
module = types.ModuleType(name)
4445
module.__file__ = '<test>'
4546
module.__package__ = ''
4647
with util.uncache(name):

0 commit comments

Comments
 (0)