autoclasstoc.Section
- class autoclasstoc.Section(state, cls)
Format a specific section in a class TOC, e.g. “Public Methods”.
The purpose of this class is to make it easy to customize the sections that make up the class TOC. For example, you might want an “Event Handler” section that includes any method that starts with “on_”. Or you might want to format the links in a table with multiple columns, to save more space.
These kinds of things can be accomplished by subclassing
Section
and overwriting the relevant methods. Almost every method is meant to be overridden by subclasses, but most subclasses will only need to overridekey
,title
, andpredicate
.key
andtitle
have no default value, and must be overridden in each subclass.predicate
determines which attributes are included in the section, which is the primary purpose of most custom sections.Public Data Attributes:
Public Methods:
__init__
(state, cls)Create a section for a specific class.
Keep track of any
Section
subclasses that are defined.check
()Raise
ConfigError
if the section has not been configured correctly, e.g.format
()Return a list of docutils nodes that will compose the section.
predicate
(name, attr, meta)Return true if the given attribute should be included in this section.
Private Methods:
Create the container node that will contain the entire section.
Create the section header node.
_make_links
(attrs, cls)Make a link to the full documentation for each attribute.
_make_inherited_details
(parent)Make a collapsible node to contain links to inherited attributes.
_filter_attrs
(attrs)Return only those attributes that match the predicate.
Return all attributes associated with this class.
Find attributes that this class has inherited from other classes.
Full Documentation:
- __annotations__ = {}
- __init__(state, cls)[source]
Create a section for a specific class.
- Parameters:
state (docutils.parsers.rst.states.RSTState) – The state object associated with the
autoclasstoc
directive. This can be used to evaluate restructured text markup usingnodes_from_rst()
.cls (type) – The class to make the TOC section for.
- _filter_attrs(attrs)[source]
Return only those attributes that match the predicate.
- Parameters:
attrs (dict) – A dictionary of attributes, in the same format as
__dict__
. Attributes have only an annotation, but no value, will be present in this dictionary, but will have the special valueutils.ANNOTATED_ATTR
.- Returns:
A dictionary in the same format as attrs.
- _find_attrs()[source]
Return all attributes associated with this class.
These attributes will subsequently be filtered to remove any that aren’t relevant to this section, so there is no need to do any filtering here. The return value should be a name-to-attribute dictionary in the same format as
__dict__
.
- _find_inherited_attrs()[source]
Find attributes that this class has inherited from other classes.
These attributes will subsequently be filtered to remove any that aren’t relevant to this section, so there is no need to do any filtering here. The return value should be a dictionary mapping parent class types to
__dict__
style dictionaries.
- _make_container()[source]
Create the container node that will contain the entire section.
This method is meant to be overridden in subclasses. The primary purpose of the container node is to belong to a CSS class that can then be used to identify HTML elements associated with
autoclasstoc
.
- _make_inherited_details(parent)[source]
Make a collapsible node to contain links to inherited attributes.
This method is meant to be overridden in subclasses. The default implementation returns a
details
node, which is rendered in HTML as a<details>
element.
- _make_links(attrs, cls)[source]
Make a link to the full documentation for each attribute.
This method is meant to be overridden in subclasses. The default implementation creates the links using an
autosummary
directive.
- _make_rubric()[source]
Create the section header node.
This method is meant to be overridden in subclasses.
- check()[source]
Raise
ConfigError
if the section has not been configured correctly, e.g. if it doesn’t have a title specified.
- exclude_pattern = None
- exclude_section = None
- format()[source]
Return a list of docutils nodes that will compose the section.
The default implementation of this method creates and populates
autosummary
directives for the class in question and all of its superclasses.
- include_inherited = True
- key = None
- predicate(name, attr, meta)[source]
Return true if the given attribute should be included in this section.
- Parameters:
See also
- title = None