MCPcopy Index your code
hub / github.com/python/cpython / docmodule

Method docmodule

Lib/pydoc.py:1266–1365  ·  view source on GitHub ↗

Produce text documentation for a given module object.

(self, object, name=None, mod=None, *ignored)

Source from the content-addressed store, hash-verified

1264 return result
1265
1266 def docmodule(self, object, name=None, mod=None, *ignored):
1267 """Produce text documentation for a given module object."""
1268 name = object.__name__ # ignore the passed-in name
1269 synop, desc = splitdoc(getdoc(object))
1270 result = self.section('NAME', name + (synop and ' - ' + synop))
1271 all = getattr(object, '__all__', None)
1272 docloc = self.getdocloc(object)
1273 if docloc is not None:
1274 result = result + self.section('MODULE REFERENCE', docloc + """
1275
1276The following documentation is automatically generated from the Python
1277source files. It may be incomplete, incorrect or include features that
1278are considered implementation detail and may vary between Python
1279implementations. When in doubt, consult the module reference at the
1280location listed above.
1281""")
1282
1283 if desc:
1284 result = result + self.section('DESCRIPTION', desc)
1285
1286 classes = []
1287 for key, value in inspect.getmembers(object, inspect.isclass):
1288 # if __all__ exists, believe it. Otherwise use old heuristic.
1289 if (all is not None
1290 or (inspect.getmodule(value) or object) is object):
1291 if visiblename(key, all, object):
1292 classes.append((key, value))
1293 funcs = []
1294 for key, value in inspect.getmembers(object, inspect.isroutine):
1295 # if __all__ exists, believe it. Otherwise use a heuristic.
1296 if (all is not None
1297 or inspect.isbuiltin(value)
1298 or (inspect.getmodule(value) or object) is object):
1299 if visiblename(key, all, object):
1300 funcs.append((key, value))
1301 data = []
1302 for key, value in inspect.getmembers(object, isdata):
1303 if visiblename(key, all, object):
1304 data.append((key, value))
1305
1306 modpkgs = []
1307 modpkgs_names = set()
1308 if hasattr(object, '__path__'):
1309 for importer, modname, ispkg in pkgutil.iter_modules(object.__path__):
1310 modpkgs_names.add(modname)
1311 if ispkg:
1312 modpkgs.append(modname + ' (package)')
1313 else:
1314 modpkgs.append(modname)
1315
1316 modpkgs.sort()
1317 result = result + self.section(
1318 'PACKAGE CONTENTS', '\n'.join(modpkgs))
1319
1320 # Detect submodules as sometimes created by C extensions
1321 submodules = []
1322 for key, value in inspect.getmembers(object, inspect.ismodule):
1323 if value.__name__.startswith(name + '.') and key not in modpkgs_names:

Callers 2

get_pydoc_textFunction · 0.95

Calls 15

sectionMethod · 0.95
formattreeMethod · 0.95
docotherMethod · 0.95
splitdocFunction · 0.85
visiblenameFunction · 0.85
setFunction · 0.85
strFunction · 0.85
getdoclocMethod · 0.80
getmembersMethod · 0.80
documentMethod · 0.80
getdocFunction · 0.70
appendMethod · 0.45

Tested by 2

get_pydoc_textFunction · 0.76