@@ -269,54 +269,39 @@ def __init__(self, watcher, loader): |
269 | 269 | def __getattr__(self, name): |
270 | 270 | if name == "create_module" and hasattr(self.loader, name): |
271 | 271 | return self._create_module |
272 | | - if name == "load_module" and hasattr(self.loader, name): |
273 | | - return self._load_module |
274 | 272 | return getattr(self.loader, name) |
275 | 273 |
|
276 | 274 | def _create_module(self, spec): |
277 | | - spec = self.loader.create_module(spec) |
| 275 | + module_object = self.loader.create_module(spec) |
278 | 276 | if ( |
279 | 277 | getattr(spec, "origin", None) is not None |
280 | 278 | and spec.origin != "builtin" |
281 | 279 | ): |
282 | 280 | self.watcher.track_module(spec.origin) |
283 | | - return spec |
284 | | - |
285 | | - def _load_module(self, name): |
286 | | - module = self.loader.load_module(name) |
287 | | - if hasattr(module, "__file__"): |
288 | | - self.watcher.track_module(module.__file__) |
289 | | - return module |
| 281 | + return module_object |
290 | 282 |
|
291 | 283 |
|
292 | 284 | class ImportFinder: |
293 | | - """Wrapper for finders in sys.meta_path to replace wrap all loaders with ImportLoader.""" |
| 285 | + """Wrapper for finders in sys.meta_path to wrap all loaders with ImportLoader.""" |
294 | 286 |
|
295 | | - def __init__(self, finder, watcher): |
| 287 | + def __init__(self, watcher, finder): |
296 | 288 | self.watcher = watcher |
297 | 289 | self.finder = finder |
298 | 290 |
|
299 | 291 | def __getattr__(self, name): |
300 | 292 | if name == "find_spec" and hasattr(self.finder, name): |
301 | 293 | return self._find_spec |
302 | | - if name == "find_module" and hasattr(self.finder, name): |
303 | | - return self._find_module |
304 | 294 | return getattr(self.finder, name) |
305 | 295 |
|
306 | 296 | def _find_spec(self, fullname, path, target=None): |
307 | 297 | # Attempt to find the spec |
308 | 298 | spec = self.finder.find_spec(fullname, path, target) |
309 | 299 | if spec is not None: |
310 | | - if getattr(spec, "__loader__", None) is not None: |
| 300 | + if getattr(spec, "loader", None) is not None: |
311 | 301 | # Patch the loader to enable reloading |
312 | | - spec.__loader__ = ImportLoader(self.watcher, spec.__loader__) |
| 302 | + spec.loader = ImportLoader(self.watcher, spec.loader) |
313 | 303 | return spec |
314 | 304 |
|
315 | | - def _find_module(self, fullname, path=None): |
316 | | - loader = self.finder.find_module(fullname, path) |
317 | | - if loader is not None: |
318 | | - return ImportLoader(self.watcher, loader) |
319 | | - |
320 | 305 |
|
321 | 306 | def _process_ps(ps, default_ps: str): |
322 | 307 | """Replace ps1/ps2 with the default if the user specified value contains control characters.""" |
@@ -607,14 +592,7 @@ def __enter__(self): |
607 | 592 | if self.watcher: |
608 | 593 | meta_path = [] |
609 | 594 | for finder in sys.meta_path: |
610 | | - # All elements get wrapped in ImportFinder instances execepted for instances of |
611 | | - # _SixMetaPathImporter (from six). When importing six, it will check if the importer |
612 | | - # is already part of sys.meta_path and will remove instances. We do not want to |
613 | | - # break this feature (see also #874). |
614 | | - if type(finder).__name__ == "_SixMetaPathImporter": |
615 | | - meta_path.append(finder) |
616 | | - else: |
617 | | - meta_path.append(ImportFinder(finder, self.watcher)) |
| 595 | + meta_path.append(ImportFinder(self.watcher, finder)) |
618 | 596 | sys.meta_path = meta_path |
619 | 597 |
|
620 | 598 | sitefix.monkeypatch_quit() |
|