From e51a36922ffcce8c5e45cc88dc95a9d33ead0f11 Mon Sep 17 00:00:00 2001 From: "Eric V. Smith" Date: Sun, 24 Jun 2012 19:13:55 -0400 Subject: Fixes issue 15039: namespace packages are no longer imported in preference to modules of the same name. --- Lib/importlib/_bootstrap.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'Lib/importlib/_bootstrap.py') diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py index 40d500ada21..36c0e88cace 100644 --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -1090,6 +1090,7 @@ class FileFinder: def find_loader(self, fullname): """Try to find a loader for the specified module, or the namespace package portions. Returns (loader, list-of-portions).""" + is_namespace = False tail_module = fullname.rpartition('.')[2] try: mtime = _os.stat(self.path).st_mtime @@ -1115,14 +1116,17 @@ class FileFinder: if _path_isfile(full_path): return (loader(fullname, full_path), [base_path]) else: - # A namespace package, return the path - return (None, [base_path]) + # A namespace package, return the path if we don't also + # find a module in the next section. + is_namespace = True # Check for a file w/ a proper suffix exists. for suffix, loader in self.modules: if cache_module + suffix in cache: full_path = _path_join(self.path, tail_module + suffix) if _path_isfile(full_path): return (loader(fullname, full_path), []) + if is_namespace: + return (None, [base_path]) return (None, []) def _fill_cache(self): -- cgit v1.2.3