def _augment_attributes()

in tools/tensorflow_docs/api_generator/pretty_docs/class_page.py [0:0]


  def _augment_attributes(
      self, docstring_parts: List[Any]) -> Optional[parser.TitleBlock]:
    """Augments and deletes the "Attr" block of the docstring.

    The augmented block is returned and then added to the markdown page by
    pretty_docs.py. The existing Attribute block is deleted from the docstring.

    Merges `namedtuple` fields and properties into the attrs block.

    + `namedtuple` fields first, in order.
    + Then the docstring `Attr:` block.
    + Then any `properties` or `dataclass` fields not mentioned above.

    Args:
      docstring_parts: A list of docstring parts.

    Returns:
      Augmented "Attr" block.
    """

    attribute_block = None

    for attr_block_index, part in enumerate(docstring_parts):
      if isinstance(part, parser.TitleBlock) and part.title.startswith('Attr'):
        raw_attrs = collections.OrderedDict(part.items)
        break
    else:
      # Didn't find the attributes block, there may still be attributes so
      # add a placeholder for them at the end.
      raw_attrs = collections.OrderedDict()
      attr_block_index = len(docstring_parts)
      docstring_parts.append(None)

    attrs = collections.OrderedDict()
    # namedtuple fields first, in order.
    for name, desc in self._namedtuplefields.items():
      # If a namedtuple field has been filtered out, it's description will
      # not have been set in loop in `collect_docs`, so skip fields with `None`
      # as the description.
      if desc is not None:
        attrs[name] = desc
    # the contents of the `Attrs:` block from the docstring
    attrs.update(raw_attrs)

    # properties and dataclass fields last.
    for name, desc in self._properties.items():
      # Don't overwrite existing items
      attrs.setdefault(name, desc)

    if dataclasses.is_dataclass(self.py_object):
      for name, desc in self._dataclass_fields().items():
        # Don't overwrite existing items
        attrs.setdefault(name, desc)

    if attrs:
      attribute_block = parser.TitleBlock(
          title='Attributes', text='', items=list(attrs.items()))

    # Delete the Attrs block if it exists or delete the placeholder.
    del docstring_parts[attr_block_index]

    return attribute_block