Python numpydoc.docscrape.NumpyDocString() Examples
The following are 9
code examples of numpydoc.docscrape.NumpyDocString().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
numpydoc.docscrape
, or try the search function
.
Example #1
Source File: numpydoc_utils.py From nucleus7 with Mozilla Public License 2.0 | 6 votes |
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
Example #2
Source File: configuration.py From magnitude with MIT License | 5 votes |
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
Example #3
Source File: numpydocstrings.py From blackmamba with MIT License | 5 votes |
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 []
Example #4
Source File: test_docscrape.py From artview with BSD 3-Clause "New" or "Revised" License | 5 votes |
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']
Example #5
Source File: test_docscrape.py From artview with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)'
Example #6
Source File: docstrings.py From python-tools with MIT License | 5 votes |
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 []
Example #7
Source File: docstrings.py From autocomplete-python with GNU General Public License v2.0 | 5 votes |
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 []
Example #8
Source File: test_docscrape.py From queueing-tool with MIT License | 5 votes |
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']
Example #9
Source File: test_docscrape.py From queueing-tool with MIT License | 5 votes |
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)'