|
5 | 5 | from importlib.machinery import SOURCE_SUFFIXES, ModuleSpec |
6 | 6 | from os.path import join |
7 | 7 | from types import ModuleType |
8 | | -from typing import TYPE_CHECKING |
| 8 | +from typing import TYPE_CHECKING, Any |
9 | 9 |
|
10 | 10 | from fsspec import url_to_fs |
11 | 11 | from fsspec.implementations.local import AbstractFileSystem |
|
28 | 28 | class FSSpecImportFinder(MetaPathFinder): |
29 | 29 | def __init__(self, fs: PythonFileSystem) -> None: |
30 | 30 | self.fs: PythonFileSystem = fs |
31 | | - self.remote_modules: dict[str, str] = {} |
| 31 | + self.remote_modules: dict[str, ModuleSpec] = {} |
32 | 32 |
|
33 | 33 | def find_spec(self, fullname: str, path: Sequence[str | bytes] | None, target: ModuleType | None = None) -> ModuleSpec | None: |
34 | 34 | for suffix in SOURCE_SUFFIXES: |
@@ -76,7 +76,7 @@ def get_data(self, path: str | bytes) -> bytes: |
76 | 76 | # source = source_bytes.decode("utf-8") |
77 | 77 |
|
78 | 78 |
|
79 | | -def install_importer(fs: str | AbstractFileSystem, **kwargs: str) -> FSSpecImportFinder: |
| 79 | +def install_importer(fs: str | AbstractFileSystem, **kwargs: Any) -> PythonFileSystem: |
80 | 80 | """Install the fsspec importer.""" |
81 | 81 | if isinstance(fs, AbstractFileSystem): |
82 | 82 | fsspec_str = normalize_fsspec(fs=fs, **kwargs) |
@@ -106,9 +106,8 @@ def uninstall_importer(fs: str | AbstractFileSystem = "") -> None: |
106 | 106 | fsspec_str = normalize_fsspec(fs=fs) if isinstance(fs, AbstractFileSystem) else fs |
107 | 107 |
|
108 | 108 | if fsspec_str in _finders: |
109 | | - finder = _finders.pop(fsspec_str, None) |
110 | | - if finder: |
111 | | - finder.unload() |
| 109 | + finder = _finders.pop(fsspec_str) |
| 110 | + finder.unload() |
112 | 111 | if finder in sys.meta_path: |
113 | 112 | sys.meta_path.remove(finder) |
114 | 113 | return |
|
0 commit comments