Skip to content

Commit

Permalink
Don't use global var
Browse files Browse the repository at this point in the history
- wallrusify
- add a note about deffered import
  • Loading branch information
danielhollas committed Aug 20, 2024
1 parent 8e66fbc commit debb516
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions importlib_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1070,9 +1070,6 @@ def _topmost(name: PackagePath) -> Optional[str]:
return top if rest else None


inspect = None


def _get_toplevel_name(name: PackagePath) -> str:
"""
Infer a possibly importable module name from a name presumed on
Expand All @@ -1091,13 +1088,12 @@ def _get_toplevel_name(name: PackagePath) -> str:
>>> _get_toplevel_name(PackagePath('foo.dist-info'))
'foo.dist-info'
"""
n = _topmost(name)
if n:
if n := _topmost(name):
return n

global inspect
if inspect is None:
import inspect
# We're deffering import of inspect to speed up overall import time
import inspect

return inspect.getmodulename(name) or str(name)


Expand Down

0 comments on commit debb516

Please sign in to comment.