本文整理汇总了Python中numpydoc.docscrape.ClassDoc方法的典型用法代码示例。如果您正苦于以下问题:Python docscrape.ClassDoc方法的具体用法?Python docscrape.ClassDoc怎么用?Python docscrape.ClassDoc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpydoc.docscrape
的用法示例。
在下文中一共展示了docscrape.ClassDoc方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: find_documented_attributes
# 需要导入模块: from numpydoc import docscrape [as 别名]
# 或者: from numpydoc.docscrape import ClassDoc [as 别名]
def find_documented_attributes(class_name, attrs):
"""Parse the documentation to retrieve all attributes that have been
documented and their documentation
"""
# If a class is not documented we return an empty list
if '__doc__' not in attrs:
return []
current_class_doc = inspect.cleandoc(attrs['__doc__'])
parsed_doc = docscrape.ClassDoc(None, doc=current_class_doc)
attr_docs = parsed_doc['Parameters'] + parsed_doc['Attributes'] + \
parsed_doc['Other Parameters']
attr_and_doc = []
create_property_doc = BaseMeta.create_property_doc
for attr_doc in attr_docs:
attr_name = attr_doc[0]
if ':' in attr_name:
raise ValueError("Attribute '%s' has not a proper "
"documentation, a space might be missing "
"before colon" % attr_name)
attr_and_doc += [(attr_name,
create_property_doc(class_name, attr_doc))]
return attr_and_doc
示例2: test_docstring_parameters
# 需要导入模块: from numpydoc import docscrape [as 别名]
# 或者: from numpydoc.docscrape import ClassDoc [as 别名]
def test_docstring_parameters():
"""Test module docstring formatting."""
from numpydoc import docscrape
public_modules_ = public_modules[:]
incorrect = []
for name in public_modules_:
with warnings.catch_warnings(record=True): # traits warnings
module = __import__(name, globals())
for submod in name.split('.')[1:]:
module = getattr(module, submod)
classes = inspect.getmembers(module, inspect.isclass)
for cname, cls in classes:
if cname.startswith('_'):
continue
with warnings.catch_warnings(record=True) as w:
cdoc = docscrape.ClassDoc(cls)
if len(w):
raise RuntimeError('Error for __init__ of %s in %s:\n%s'
% (cls, name, w[0]))
if hasattr(cls, '__init__'):
incorrect += check_parameters_match(cls.__init__, cdoc)
for method_name in cdoc.methods:
method = getattr(cls, method_name)
incorrect += check_parameters_match(method)
if hasattr(cls, '__call__'):
incorrect += check_parameters_match(cls.__call__)
functions = inspect.getmembers(module, inspect.isfunction)
for fname, func in functions:
if fname.startswith('_'):
continue
incorrect += check_parameters_match(func)
msg = '\n' + '\n'.join(sorted(list(set(incorrect))))
if len(incorrect) > 0:
raise AssertionError(msg)
示例3: _get_help_for_estimator
# 需要导入模块: from numpydoc import docscrape [as 别名]
# 或者: from numpydoc.docscrape import ClassDoc [as 别名]
def _get_help_for_estimator(prefix, estimator, defaults=None):
"""Yield help lines for the given estimator and prefix."""
from numpydoc.docscrape import ClassDoc
defaults = defaults or {}
estimator = _extract_estimator_cls(estimator)
yield "<{}> options:".format(estimator.__name__)
doc = ClassDoc(estimator)
yield from _get_help_for_params(
doc['Parameters'],
prefix=prefix,
defaults=defaults,
)
yield '' # add a newline line between estimators
示例4: test_class_members
# 需要导入模块: from numpydoc import docscrape [as 别名]
# 或者: from numpydoc.docscrape import ClassDoc [as 别名]
def test_class_members():
class Dummy(object):
"""
Dummy class.
"""
def spam(self, a, b):
"""Spam\n\nSpam spam."""
pass
def ham(self, c, d):
"""Cheese\n\nNo cheese."""
pass
@property
def spammity(self):
"""Spammity index"""
return 0.95
class Ignorable(object):
"""local class, to be ignored"""
pass
for cls in (ClassDoc, SphinxClassDoc):
doc = cls(Dummy, config=dict(show_class_members=False))
assert 'Methods' not in str(doc), (cls, str(doc))
assert 'spam' not in str(doc), (cls, str(doc))
assert 'ham' not in str(doc), (cls, str(doc))
assert 'spammity' not in str(doc), (cls, str(doc))
assert 'Spammity index' not in str(doc), (cls, str(doc))
doc = cls(Dummy, config=dict(show_class_members=True))
assert 'Methods' in str(doc), (cls, str(doc))
assert 'spam' in str(doc), (cls, str(doc))
assert 'ham' in str(doc), (cls, str(doc))
assert 'spammity' in str(doc), (cls, str(doc))
if cls is SphinxClassDoc:
assert '.. autosummary::' in str(doc), str(doc)
else:
assert 'Spammity index' in str(doc), str(doc)
示例5: test_class_members_doc
# 需要导入模块: from numpydoc import docscrape [as 别名]
# 或者: from numpydoc.docscrape import ClassDoc [as 别名]
def test_class_members_doc():
doc = ClassDoc(None, class_doc_txt)
non_blank_line_by_line_compare(str(doc),
"""
Foo
Parameters
----------
f : callable ``f(t, y, *f_args)``
Aaa.
jac : callable ``jac(t, y, *jac_args)``
Bbb.
Examples
--------
For usage examples, see `ode`.
Attributes
----------
t : float
Current time.
y : ndarray
Current variable values.
Methods
-------
a :
b :
c :
.. index::
""")
示例6: test_class_members_doc
# 需要导入模块: from numpydoc import docscrape [as 别名]
# 或者: from numpydoc.docscrape import ClassDoc [as 别名]
def test_class_members_doc():
doc = ClassDoc(None, class_doc_txt)
non_blank_line_by_line_compare(str(doc),
"""
Foo
Parameters
----------
f : callable ``f(t, y, *f_args)``
Aaa.
jac : callable ``jac(t, y, *jac_args)``
Bbb.
Examples
--------
For usage examples, see `ode`.
Attributes
----------
t : float
Current time.
y : ndarray
Current variable values.
Methods
-------
a
b
c
.. index::
""")