当前位置: 首页>>代码示例>>Python>>正文


Python docscrape.NumpyDocString方法代码示例

本文整理汇总了Python中numpydoc.docscrape.NumpyDocString方法的典型用法代码示例。如果您正苦于以下问题:Python docscrape.NumpyDocString方法的具体用法?Python docscrape.NumpyDocString怎么用?Python docscrape.NumpyDocString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在numpydoc.docscrape的用法示例。


在下文中一共展示了docscrape.NumpyDocString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: doc_from_method

# 需要导入模块: from numpydoc import docscrape [as 别名]
# 或者: from numpydoc.docscrape import NumpyDocString [as 别名]
def doc_from_method(method: Callable) -> Union[NumpyDocString, dict]:
    """
    Read the docstring from method to NumpyDocString format

    Parameters
    ----------
    method
        callable to inspect

    Returns
    -------
    docstring
        docstring
    """
    doc = method.__doc__
    if doc is None:
        return {}

    if not doc[:1] == '\n':
        doc = '\n    ' + doc
    doc = NumpyDocString(doc)
    return doc 
开发者ID:audi,项目名称:nucleus7,代码行数:24,代码来源:numpydoc_utils.py

示例2: _docspec_comments

# 需要导入模块: from numpydoc import docscrape [as 别名]
# 或者: from numpydoc.docscrape import NumpyDocString [as 别名]
def _docspec_comments(obj)                  :
    u"""
    Inspect the docstring and get the comments for each parameter.
    """
    # Sometimes our docstring is on the class, and sometimes it's on the initializer,
    # so we've got to check both.
    class_docstring = getattr(obj, u'__doc__', None)
    init_docstring = getattr(obj.__init__, u'__doc__', None) if hasattr(obj, u'__init__') else None

    docstring = class_docstring or init_docstring or u''

    doc = NumpyDocString(docstring)
    params = doc[u"Parameters"]
    comments                 = {}

    for line in params:
        # It looks like when there's not a space after the parameter name,
        # numpydocstring parses it incorrectly.
        name_bad = line[0]
        name = name_bad.split(u":")[0]

        # Sometimes the line has 3 fields, sometimes it has 4 fields.
        comment = u"\n".join(line[-1])

        comments[name] = comment

    return comments 
开发者ID:plasticityai,项目名称:magnitude,代码行数:29,代码来源:configuration.py

示例3: __call__

# 需要导入模块: from numpydoc import docscrape [as 别名]
# 或者: from numpydoc.docscrape import NumpyDocString [as 别名]
def __call__(self, docstring, param_name):
        """Search `docstring` (in numpydoc format) for type(-s) of `param_name`."""
        params = NumpyDocString(docstring)._parsed_data['Parameters']
        for p_name, p_type, p_descr in params:
            if p_name == param_name:
                m = re.match('([^,]+(,[^,]+)*?)(,[ ]*optional)?$', p_type)
                if m:
                    p_type = m.group(1)

                if p_type.startswith('{'):
                    types = set(type(x).__name__ for x in literal_eval(p_type))
                    return list(types)
                else:
                    return [p_type]
        return [] 
开发者ID:zrzka,项目名称:blackmamba,代码行数:17,代码来源:numpydocstrings.py

示例4: test_see_also

# 需要导入模块: from numpydoc import docscrape [as 别名]
# 或者: from numpydoc.docscrape import NumpyDocString [as 别名]
def test_see_also():
    doc6 = NumpyDocString(
    """
    z(x,theta)

    See Also
    --------
    func_a, func_b, func_c
    func_d : some equivalent func
    foo.func_e : some other func over
             multiple lines
    func_f, func_g, :meth:`func_h`, func_j,
    func_k
    :obj:`baz.obj_q`
    :class:`class_j`: fubar
        foobar
    """)

    assert len(doc6['See Also']) == 12
    for func, desc, role in doc6['See Also']:
        if func in ('func_a', 'func_b', 'func_c', 'func_f',
                    'func_g', 'func_h', 'func_j', 'func_k', 'baz.obj_q'):
            assert(not desc)
        else:
            assert(desc)

        if func == 'func_h':
            assert role == 'meth'
        elif func == 'baz.obj_q':
            assert role == 'obj'
        elif func == 'class_j':
            assert role == 'class'
        else:
            assert role is None

        if func == 'func_d':
            assert desc == ['some equivalent func']
        elif func == 'foo.func_e':
            assert desc == ['some other func over', 'multiple lines']
        elif func == 'class_j':
            assert desc == ['fubar', 'foobar'] 
开发者ID:nguy,项目名称:artview,代码行数:43,代码来源:test_docscrape.py

示例5: test_duplicate_signature

# 需要导入模块: from numpydoc import docscrape [as 别名]
# 或者: from numpydoc.docscrape import NumpyDocString [as 别名]
def test_duplicate_signature():
    # Duplicate function signatures occur e.g. in ufuncs, when the
    # automatic mechanism adds one, and a more detailed comes from the
    # docstring itself.

    doc = NumpyDocString(
    """
    z(x1, x2)

    z(a, theta)
    """)

    assert doc['Signature'].strip() == 'z(a, theta)' 
开发者ID:nguy,项目名称:artview,代码行数:15,代码来源:test_docscrape.py

示例6: _search_param_in_numpydocstr

# 需要导入模块: from numpydoc import docscrape [as 别名]
# 或者: from numpydoc.docscrape import NumpyDocString [as 别名]
def _search_param_in_numpydocstr(docstr, param_str):
        """Search `docstr` (in numpydoc format) for type(-s) of `param_str`."""
        params = NumpyDocString(docstr)._parsed_data['Parameters']
        for p_name, p_type, p_descr in params:
            if p_name == param_str:
                m = re.match('([^,]+(,[^,]+)*?)(,[ ]*optional)?$', p_type)
                if m:
                    p_type = m.group(1)

                if p_type.startswith('{'):
                    types = set(type(x).__name__ for x in literal_eval(p_type))
                    return list(types)
                else:
                    return [p_type]
        return [] 
开发者ID:MichaelAquilina,项目名称:python-tools,代码行数:17,代码来源:docstrings.py


注:本文中的numpydoc.docscrape.NumpyDocString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。