]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Fix pyclbr to support importing packages
authorVictor Stinner <victor.stinner@gmail.com>
Thu, 17 Mar 2016 08:06:41 +0000 (09:06 +0100)
committerVictor Stinner <victor.stinner@gmail.com>
Thu, 17 Mar 2016 08:06:41 +0000 (09:06 +0100)
Issue #26569: Fix pyclbr.readmodule() and pyclbr.readmodule_ex() to support
importing packages.

Lib/pyclbr.py
Misc/NEWS

index dd58ada0aa5200038c77fe9f289e04839ffce8b1..4d40b87f164ecc33baeb4db755a513318f4f7c06 100644 (file)
@@ -142,10 +142,10 @@ def _readmodule(module, path, inpackage=None):
         search_path = path + sys.path
     # XXX This will change once issue19944 lands.
     spec = importlib.util._find_spec_from_path(fullmodule, search_path)
-    fname = spec.loader.get_filename(fullmodule)
     _modules[fullmodule] = dict
-    if spec.loader.is_package(fullmodule):
-        dict['__path__'] = [os.path.dirname(fname)]
+    # is module a package?
+    if spec.submodule_search_locations is not None:
+        dict['__path__'] = spec.submodule_search_locations
     try:
         source = spec.loader.get_source(fullmodule)
         if source is None:
@@ -154,6 +154,8 @@ def _readmodule(module, path, inpackage=None):
         # not Python source, can't do anything with this module
         return dict
 
+    fname = spec.loader.get_filename(fullmodule)
+
     f = io.StringIO(source)
 
     stack = [] # stack of (class, indent) pairs
index eef7f0164f407a2ba01cd3bd8068c9ac715a1454..4299e4e1db2476dbf4489d9613451c4ad4874b49 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -91,6 +91,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #26569: Fix :func:`pyclbr.readmodule` and :func:`pyclbr.readmodule_ex`
+  to support importing packages.
+
 - Issue #26499: Account for remaining Content-Length in
   HTTPResponse.readline() and read1().  Based on patch by Silent Ghost.
   Also document that HTTPResponse now supports these methods.