def _add_method()

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


  def _add_method(
      self,
      member_info: base_page.MemberInfo,
      defining_class: Optional[type],  # pylint: disable=g-bare-generic
      parser_config: config.ParserConfig) -> None:
    """Adds a `MethodInfo` entry to the `methods` list.

    Args:
      member_info: a `base_page.MemberInfo` describing the method.
      defining_class: The `type` object where this method is defined.
      parser_config: A `config.ParserConfig`.
    """
    if defining_class is None:
      return

    # Omit methods defined by namedtuple.
    original_method = defining_class.__dict__[member_info.short_name]
    if (hasattr(original_method, '__module__') and
        (original_method.__module__ or '').startswith('namedtuple')):
      return

    # Some methods are often overridden without documentation. Because it's
    # obvious what they do, don't include them in the docs if there's no
    # docstring.
    if (not member_info.doc.brief.strip() and
        member_info.short_name in ['__del__', '__copy__']):
      return

    # If the current class py_object is a dataclass then use the class object
    # instead of the __init__ method object because __init__ is a
    # generated method on dataclasses (unless the definition used init=False)
    # and `inspect.getsource` doesn't work on generated methods (as the source
    # file doesn't exist) which is required for signature generation.
    if (dataclasses.is_dataclass(self.py_object) and
        member_info.short_name == '__init__' and
        self.py_object.__dataclass_params__.init):
      is_dataclass = True
      py_obj = self.py_object
    else:
      is_dataclass = False
      py_obj = member_info.py_object

    func_type = signature_lib.get_method_type(original_method,
                                              member_info.short_name,
                                              is_dataclass)
    signature = signature_lib.generate_signature(
        py_obj, parser_config, member_info.full_name, func_type=func_type)

    decorators = signature_lib.extract_decorators(member_info.py_object)

    defined_in = parser.get_defined_in(member_info.py_object, parser_config)

    method_info = MethodInfo.from_member_info(member_info, signature,
                                              decorators, defined_in)
    self._methods.append(method_info)