Example #1
0
def Info(component):
    """Returns a dict with information about the given component.

  The dict will have at least some of the following fields.
    type_name: The type of `component`.
    string_form: A string representation of `component`.
    file: The file in which `component` is defined.
    line: The line number at which `component` is defined.
    docstring: The docstring of `component`.
    init_docstring: The init docstring of `component`.
    class_docstring: The class docstring of `component`.
    call_docstring: The call docstring of `component`.
    length: The length of `component`.

  Args:
    component: The component to analyze.
  Returns:
    A dict with information about the component.
  """
    try:
        from IPython.core import oinspect  # pylint: disable=g-import-not-at-top
        inspector = oinspect.Inspector()
        info = inspector.info(component)
    except ImportError:
        info = _InfoBackup(component)

    try:
        unused_code, lineindex = inspect.findsource(component)
        info['line'] = lineindex + 1
    except (TypeError, IOError):
        info['line'] = None

    return info
Example #2
0
def Info(component):
    """Returns a dict with information about the given component.

    The dict will have at least some of the following fields.
      type_name: The type of `component`.
      string_form: A string representation of `component`.
      file: The file in which `component` is defined.
      line: The line number at which `component` is defined.
      docstring: The docstring of `component`.
      init_docstring: The init docstring of `component`.
      class_docstring: The class docstring of `component`.
      call_docstring: The call docstring of `component`.
      length: The length of `component`.

    Args:
      component: The component to analyze.
    Returns:
      A dict with information about the component.
    """
    try:
        from IPython.core import (
            oinspect, )  # pylint: disable=import-outside-toplevel,g-import-not-at-top

        inspector = oinspect.Inspector()
        info = inspector.info(component)

        # IPython's oinspect.Inspector.info may return '<no docstring>'
        if info["docstring"] == "<no docstring>":
            info["docstring"] = None
    except ImportError:
        info = _InfoBackup(component)

    try:
        unused_code, lineindex = inspect.findsource(component)
        info["line"] = lineindex + 1
    except (TypeError, IOError):
        info["line"] = None

    if "docstring" in info:
        info["docstring_info"] = docstrings.parse(info["docstring"])

    return info