Skip to content

Commit

Permalink
Merge pull request #499 from danielhollas/defer-inspect
Browse files Browse the repository at this point in the history
Speed up import time by deferring inspect
  • Loading branch information
jaraco authored Aug 20, 2024
2 parents 3c8e1ec + a7aaf72 commit 2c43cfe
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion importlib_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import zipp
import email
import types
import inspect
import pathlib
import operator
import textwrap
Expand Down Expand Up @@ -1106,6 +1105,9 @@ def _get_toplevel_name(name: PackagePath) -> str:
>>> _get_toplevel_name(PackagePath('foo.dist-info'))
'foo.dist-info'
"""
# Defer import of inspect for performance (python/cpython#118761)
import inspect

return _topmost(name) or (
# python/typeshed#10328
inspect.getmodulename(name) # type: ignore
Expand Down

0 comments on commit 2c43cfe

Please sign in to comment.