From a453c02cf14f12360bc51efce5d687e89af61646 Mon Sep 17 00:00:00 2001 From: Tomas Babej Date: Fri, 31 Jul 2020 02:23:50 -0400 Subject: [PATCH] ImportFinder: Support find_spec interface --- bpython/curtsiesfrontend/repl.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/bpython/curtsiesfrontend/repl.py b/bpython/curtsiesfrontend/repl.py index e060ff84c..841ce582a 100644 --- a/bpython/curtsiesfrontend/repl.py +++ b/bpython/curtsiesfrontend/repl.py @@ -287,6 +287,18 @@ def find_distributions(self, context): return None + def find_spec(self, fullname, path, target=None): + for finder in self.old_meta_path: + # Consider the finder only if it implements find_spec + if not getattr(finder, "find_spec", None): + continue + # Attempt to find the spec + spec = finder.find_spec(fullname, path, target) + if spec is not None: + # Patch the loader to enable reloading + spec.__loader__ = ImportLoader(self.watcher, spec.__loader__) + return spec + def find_module(self, fullname, path=None): for finder in self.old_meta_path: loader = finder.find_module(fullname, path)