Skip to content

Commit 2c43cfe

Browse files
authored
Merge pull request #499 from danielhollas/defer-inspect
Speed up import time by deferring inspect
2 parents 3c8e1ec + a7aaf72 commit 2c43cfe

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

importlib_metadata/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import zipp
99
import email
1010
import types
11-
import inspect
1211
import pathlib
1312
import operator
1413
import textwrap
@@ -1106,6 +1105,9 @@ def _get_toplevel_name(name: PackagePath) -> str:
11061105
>>> _get_toplevel_name(PackagePath('foo.dist-info'))
11071106
'foo.dist-info'
11081107
"""
1108+
# Defer import of inspect for performance (python/cpython#118761)
1109+
import inspect
1110+
11091111
return _topmost(name) or (
11101112
# python/typeshed#10328
11111113
inspect.getmodulename(name) # type: ignore

0 commit comments

Comments
 (0)