Skip to content

Commit

Permalink
gh-98040: Fix importbench: use types.ModuleType() (#105743)
Browse files Browse the repository at this point in the history
Replace removed imp.new_module(name) with types.ModuleType(name).
  • Loading branch information
vstinner authored Jun 13, 2023
1 parent 757b402 commit 457a459
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Doc/whatsnew/3.12.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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>`_.
Expand Down
3 changes: 2 additions & 1 deletion Tools/importbench/importbench.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import sys
import tabnanny
import timeit
import types


def bench(name, cleanup=lambda: None, *, seconds=1, repeat=3):
Expand All @@ -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):
Expand Down

0 comments on commit 457a459

Please sign in to comment.