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

Method docclass

Lib/pydoc.py:1367–1515  ·  view source on GitHub ↗

Produce text documentation for a given class object.

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

Source from the content-addressed store, hash-verified

1365 return result
1366
1367 def docclass(self, object, name=None, mod=None, *ignored):
1368 """Produce text documentation for a given class object."""
1369 realname = object.__name__
1370 name = name or realname
1371 bases = object.__bases__
1372
1373 def makename(c, m=object.__module__):
1374 return classname(c, m)
1375
1376 if name == realname:
1377 title = 'class ' + self.bold(realname)
1378 else:
1379 title = self.bold(name) + ' = class ' + realname
1380 if bases:
1381 parents = map(makename, bases)
1382 title = title + '(%s)' % ', '.join(parents)
1383
1384 contents = []
1385 push = contents.append
1386
1387 argspec = _getargspec(object)
1388 if argspec and argspec != '()':
1389 push(name + argspec + '\n')
1390
1391 doc = getdoc(object)
1392 if doc:
1393 push(doc + '\n')
1394
1395 # List the mro, if non-trivial.
1396 mro = deque(inspect.getmro(object))
1397 if len(mro) > 2:
1398 push("Method resolution order:")
1399 for base in mro:
1400 push(' ' + makename(base))
1401 push('')
1402
1403 # List the built-in subclasses, if any:
1404 subclasses = sorted(
1405 (str(cls.__name__) for cls in type.__subclasses__(object)
1406 if (not cls.__name__.startswith("_") and
1407 getattr(cls, '__module__', '') == "builtins")),
1408 key=str.lower
1409 )
1410 no_of_subclasses = len(subclasses)
1411 MAX_SUBCLASSES_TO_DISPLAY = 4
1412 if subclasses:
1413 push("Built-in subclasses:")
1414 for subclassname in subclasses[:MAX_SUBCLASSES_TO_DISPLAY]:
1415 push(' ' + subclassname)
1416 if no_of_subclasses > MAX_SUBCLASSES_TO_DISPLAY:
1417 push(' ... and ' +
1418 str(no_of_subclasses - MAX_SUBCLASSES_TO_DISPLAY) +
1419 ' other subclasses')
1420 push('')
1421
1422 # Cute little class to pump out a horizontal rule between sections.
1423 class HorizontalRule:
1424 def __init__(self):

Calls 14

boldMethod · 0.95
indentMethod · 0.95
_getargspecFunction · 0.85
strFunction · 0.85
visiblenameFunction · 0.85
_split_listFunction · 0.85
classnameFunction · 0.85
sort_attributesFunction · 0.85
getdocFunction · 0.70
HorizontalRuleClass · 0.70
classify_class_attrsFunction · 0.70
joinMethod · 0.45