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

Skip to content

Commit 33675db

Browse files
committed
strict typing of IPython/utils/module_paths.py
1 parent 250a82d commit 33675db

2 files changed

Lines changed: 9 additions & 3 deletions

File tree

IPython/utils/module_paths.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
Utility 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
#
@@ -17,6 +19,8 @@
1719

1820
# Stdlib imports
1921
import importlib
22+
import importlib.abc
23+
import importlib.util
2024
import sys
2125

2226
# Third-party imports
@@ -36,7 +40,7 @@
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:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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
]
154155
check_untyped_defs = true
155156
disallow_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",

0 commit comments

Comments
 (0)