MCPcopy Index your code
hub / github.com/RustPython/RustPython / docclass

Method docclass

Lib/pydoc.py:1413–1561  ·  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

1411 return result
1412
1413 def docclass(self, object, name=None, mod=None, *ignored):
1414 """Produce text documentation for a given class object."""
1415 realname = object.__name__
1416 name = name or realname
1417 bases = object.__bases__
1418
1419 def makename(c, m=object.__module__):
1420 return classname(c, m)
1421
1422 if name == realname:
1423 title = 'class ' + self.bold(realname)
1424 else:
1425 title = self.bold(name) + ' = class ' + realname
1426 if bases:
1427 parents = map(makename, bases)
1428 title = title + '(%s)' % ', '.join(parents)
1429
1430 contents = []
1431 push = contents.append
1432
1433 argspec = _getargspec(object)
1434 if argspec and argspec != '()':
1435 push(name + argspec + '\n')
1436
1437 doc = getdoc(object)
1438 if doc:
1439 push(doc + '\n')
1440
1441 # List the mro, if non-trivial.
1442 mro = deque(inspect.getmro(object))
1443 if len(mro) > 2:
1444 push("Method resolution order:")
1445 for base in mro:
1446 push(' ' + makename(base))
1447 push('')
1448
1449 # List the built-in subclasses, if any:
1450 subclasses = sorted(
1451 (str(cls.__name__) for cls in type.__subclasses__(object)
1452 if (not cls.__name__.startswith("_") and
1453 getattr(cls, '__module__', '') == "builtins")),
1454 key=str.lower
1455 )
1456 no_of_subclasses = len(subclasses)
1457 MAX_SUBCLASSES_TO_DISPLAY = 4
1458 if subclasses:
1459 push("Built-in subclasses:")
1460 for subclassname in subclasses[:MAX_SUBCLASSES_TO_DISPLAY]:
1461 push(' ' + subclassname)
1462 if no_of_subclasses > MAX_SUBCLASSES_TO_DISPLAY:
1463 push(' ... and ' +
1464 str(no_of_subclasses - MAX_SUBCLASSES_TO_DISPLAY) +
1465 ' other subclasses')
1466 push('')
1467
1468 # Cute little class to pump out a horizontal rule between sections.
1469 class HorizontalRule:
1470 def __init__(self):

Calls 15

boldMethod · 0.95
indentMethod · 0.95
_getargspecFunction · 0.85
lenFunction · 0.85
sortedFunction · 0.85
strFunction · 0.85
getattrFunction · 0.85
visiblenameFunction · 0.85
_split_listFunction · 0.85
classnameFunction · 0.85
sort_attributesFunction · 0.85
__subclasses__Method · 0.80