]> granicus.if.org Git - python/commitdiff
#1715: include sub-extension modules in pydoc text output.
authorGeorg Brandl <georg@python.org>
Mon, 21 Jan 2008 21:05:49 +0000 (21:05 +0000)
committerGeorg Brandl <georg@python.org>
Mon, 21 Jan 2008 21:05:49 +0000 (21:05 +0000)
Lib/pydoc.py
Lib/test/pydocfodder.py
Misc/NEWS

index c2b2088ef30e058387c7e6357bb0297193e1945c..26cd55d601bc451d953bbb9036ce1b0fcef37902 100755 (executable)
@@ -1051,9 +1051,11 @@ class TextDoc(Doc):
             if visiblename(key, all):
                 data.append((key, value))
 
+        modpkgs = []
+        modpkgs_names = set()
         if hasattr(object, '__path__'):
-            modpkgs = []
             for importer, modname, ispkg in pkgutil.iter_modules(object.__path__):
+                modpkgs_names.add(modname)
                 if ispkg:
                     modpkgs.append(modname + ' (package)')
                 else:
@@ -1063,6 +1065,16 @@ class TextDoc(Doc):
             result = result + self.section(
                 'PACKAGE CONTENTS', join(modpkgs, '\n'))
 
+        # Detect submodules as sometimes created by C extensions
+        submodules = []
+        for key, value in inspect.getmembers(object, inspect.ismodule):
+            if value.__name__.startswith(name + '.') and key not in modpkgs_names:
+                submodules.append(key)
+        if submodules:
+            submodules.sort()
+            result = result + self.section(
+                'SUBMODULES', join(submodules, '\n'))
+
         if classes:
             classlist = map(lambda (key, value): value, classes)
             contents = [self.formattree(
index becdf2250e8aabe37aabc0c195b8dfe5fe68b872..2cf1cbdc04856a8d72477c6dca4171cf494fc424 100644 (file)
@@ -1,5 +1,7 @@
 """Something just to look at via pydoc."""
 
+import types
+
 class A_classic:
     "A classic class."
     def A_method(self):
@@ -208,3 +210,7 @@ class FunkyProperties(object):
             del inst.desc[self.attr]
 
     x = property(get_desc('x'), set_desc('x'), del_desc('x'), 'prop x')
+
+
+submodule = types.ModuleType(__name__ + '.submodule',
+    """A submodule, which should appear in its parent's summary""")
index 3235111f7deea02469a912694ac2d73cadd1ca62..b0a28b1443dbe27662f259dc3343215f9716e23a 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -372,6 +372,8 @@ Core and builtins
 Library
 -------
 
+- #1715: include sub-extension modules in pydoc's text output.
+
 - #1836: fix an off-by-one bug in TimedRotatingHandler's rollover
   time calculation.