當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。