inspectutils.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:python-fire 作者: google 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号