Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit debb516

Browse files
committed
Don't use global var
- wallrusify - add a note about deffered import
1 parent 8e66fbc commit debb516

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

importlib_metadata/__init__.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -1070,9 +1070,6 @@ def _topmost(name: PackagePath) -> Optional[str]:
10701070
return top if rest else None
10711071

10721072

1073-
inspect = None
1074-
1075-
10761073
def _get_toplevel_name(name: PackagePath) -> str:
10771074
"""
10781075
Infer a possibly importable module name from a name presumed on
@@ -1091,13 +1088,12 @@ def _get_toplevel_name(name: PackagePath) -> str:
10911088
>>> _get_toplevel_name(PackagePath('foo.dist-info'))
10921089
'foo.dist-info'
10931090
"""
1094-
n = _topmost(name)
1095-
if n:
1091+
if n := _topmost(name):
10961092
return n
10971093

1098-
global inspect
1099-
if inspect is None:
1100-
import inspect
1094+
# We're deffering import of inspect to speed up overall import time
1095+
import inspect
1096+
11011097
return inspect.getmodulename(name) or str(name)
11021098

11031099

0 commit comments

Comments
 (0)