File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33Utility functions for finding modules on sys.path.
44
55"""
6+ from __future__ import annotations
7+
68#-----------------------------------------------------------------------------
79# Copyright (c) 2011, the IPython Development Team.
810#
1719
1820# Stdlib imports
1921import importlib
22+ import importlib .abc
23+ import importlib .util
2024import sys
2125
2226# Third-party imports
3640# Classes and functions
3741#-----------------------------------------------------------------------------
3842
39- def find_mod (module_name ) :
43+ def find_mod (module_name : str ) -> str | None | importlib . abc . Loader :
4044 """
4145 Find module `module_name` on sys.path, and return the path to module `module_name`.
4246
@@ -59,9 +63,11 @@ def find_mod(module_name):
5963 depending on above conditions.
6064 """
6165 spec = importlib .util .find_spec (module_name )
66+ if spec is None :
67+ return None
6268 module_path = spec .origin
6369 if module_path is None :
64- if spec .loader in sys .meta_path :
70+ if spec .loader is not None and spec . loader in sys .meta_path :
6571 return spec .loader
6672 return None
6773 else :
Original file line number Diff line number Diff line change @@ -150,6 +150,7 @@ module = [
150150 " IPython.utils.syspathcontext" ,
151151 " IPython.utils.generics" ,
152152 " IPython.utils.encoding" ,
153+ " IPython.utils.module_paths" ,
153154]
154155check_untyped_defs = true
155156disallow_incomplete_defs = true
@@ -291,7 +292,6 @@ module = [
291292 " IPython.utils.frame" ,
292293 " IPython.utils.io" ,
293294 " IPython.utils.ipstruct" ,
294- " IPython.utils.module_paths" ,
295295 " IPython.utils.openpy" ,
296296 " IPython.utils.process" ,
297297 " IPython.utils.py3compat" ,
You can’t perform that action at this time.
0 commit comments