Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- .gitattributes +1 -0
- llava_next/lib/python3.10/site-packages/pyparsing/__init__.py +326 -0
- llava_next/lib/python3.10/site-packages/pyparsing/actions.py +206 -0
- llava_next/lib/python3.10/site-packages/pyparsing/exceptions.py +314 -0
- llava_next/lib/python3.10/site-packages/sniffio/__pycache__/__init__.cpython-310.pyc +0 -0
- llava_next/lib/python3.10/site-packages/sniffio/__pycache__/_impl.cpython-310.pyc +0 -0
- llava_next/lib/python3.10/site-packages/sniffio/__pycache__/_version.cpython-310.pyc +0 -0
- llava_next/lib/python3.10/site-packages/sniffio/_tests/__init__.py +0 -0
- llava_next/lib/python3.10/site-packages/sniffio/_tests/__pycache__/__init__.cpython-310.pyc +0 -0
- llava_next/lib/python3.10/site-packages/sniffio/_tests/__pycache__/test_sniffio.cpython-310.pyc +0 -0
- llava_next/lib/python3.10/site-packages/sniffio/_tests/test_sniffio.py +84 -0
- llava_next/lib/python3.10/site-packages/sniffio/_version.py +3 -0
- parrot/lib/python3.10/site-packages/docstring_parser/__init__.py +34 -0
- parrot/lib/python3.10/site-packages/docstring_parser/__pycache__/__init__.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/docstring_parser/__pycache__/common.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/docstring_parser/__pycache__/epydoc.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/docstring_parser/__pycache__/google.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/docstring_parser/__pycache__/numpydoc.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/docstring_parser/__pycache__/parser.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/docstring_parser/__pycache__/rest.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/docstring_parser/attrdoc.py +138 -0
- parrot/lib/python3.10/site-packages/docstring_parser/common.py +228 -0
- parrot/lib/python3.10/site-packages/docstring_parser/epydoc.py +268 -0
- parrot/lib/python3.10/site-packages/docstring_parser/google.py +408 -0
- parrot/lib/python3.10/site-packages/docstring_parser/numpydoc.py +532 -0
- parrot/lib/python3.10/site-packages/docstring_parser/parser.py +98 -0
- parrot/lib/python3.10/site-packages/docstring_parser/py.typed +1 -0
- parrot/lib/python3.10/site-packages/docstring_parser/rest.py +259 -0
- parrot/lib/python3.10/site-packages/docstring_parser/tests/__init__.py +1 -0
- parrot/lib/python3.10/site-packages/docstring_parser/tests/__pycache__/__init__.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/docstring_parser/tests/__pycache__/_pydoctor.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/docstring_parser/tests/__pycache__/test_epydoc.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/docstring_parser/tests/__pycache__/test_google.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/docstring_parser/tests/__pycache__/test_numpydoc.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/docstring_parser/tests/__pycache__/test_parse_from_object.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/docstring_parser/tests/__pycache__/test_parser.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/docstring_parser/tests/__pycache__/test_rest.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/docstring_parser/tests/__pycache__/test_util.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/docstring_parser/tests/_pydoctor.py +22 -0
- parrot/lib/python3.10/site-packages/docstring_parser/tests/test_epydoc.py +723 -0
- parrot/lib/python3.10/site-packages/docstring_parser/tests/test_google.py +977 -0
- parrot/lib/python3.10/site-packages/docstring_parser/tests/test_numpydoc.py +1087 -0
- parrot/lib/python3.10/site-packages/docstring_parser/tests/test_parse_from_object.py +109 -0
- parrot/lib/python3.10/site-packages/docstring_parser/tests/test_parser.py +222 -0
- parrot/lib/python3.10/site-packages/docstring_parser/tests/test_rest.py +541 -0
- parrot/lib/python3.10/site-packages/docstring_parser/tests/test_util.py +64 -0
- parrot/lib/python3.10/site-packages/docstring_parser/util.py +144 -0
- parrot/lib/python3.10/site-packages/nvidia_cusolver_cu12-11.4.5.107.dist-info/RECORD +23 -0
- parrot/lib/python3.10/site-packages/requests/__pycache__/__version__.cpython-310.pyc +0 -0
- parrot/lib/python3.10/site-packages/requests/__pycache__/adapters.cpython-310.pyc +0 -0
.gitattributes
CHANGED
|
@@ -331,3 +331,4 @@ parrot/lib/python3.10/site-packages/decord/libdecord.so filter=lfs diff=lfs merg
|
|
| 331 |
llava_next/lib/python3.10/site-packages/pandas/tests/indexing/__pycache__/test_loc.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
| 332 |
parrot/lib/python3.10/site-packages/transformers/models/seamless_m4t_v2/__pycache__/modeling_seamless_m4t_v2.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
| 333 |
parrot/lib/python3.10/site-packages/transformers/models/speecht5/__pycache__/modeling_speecht5.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 331 |
llava_next/lib/python3.10/site-packages/pandas/tests/indexing/__pycache__/test_loc.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
| 332 |
parrot/lib/python3.10/site-packages/transformers/models/seamless_m4t_v2/__pycache__/modeling_seamless_m4t_v2.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
| 333 |
parrot/lib/python3.10/site-packages/transformers/models/speecht5/__pycache__/modeling_speecht5.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
| 334 |
+
parrot/lib/python3.10/site-packages/transformers/utils/__pycache__/dummy_tf_objects.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
llava_next/lib/python3.10/site-packages/pyparsing/__init__.py
ADDED
|
@@ -0,0 +1,326 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# module pyparsing.py
|
| 2 |
+
#
|
| 3 |
+
# Copyright (c) 2003-2022 Paul T. McGuire
|
| 4 |
+
#
|
| 5 |
+
# Permission is hereby granted, free of charge, to any person obtaining
|
| 6 |
+
# a copy of this software and associated documentation files (the
|
| 7 |
+
# "Software"), to deal in the Software without restriction, including
|
| 8 |
+
# without limitation the rights to use, copy, modify, merge, publish,
|
| 9 |
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
| 10 |
+
# permit persons to whom the Software is furnished to do so, subject to
|
| 11 |
+
# the following conditions:
|
| 12 |
+
#
|
| 13 |
+
# The above copyright notice and this permission notice shall be
|
| 14 |
+
# included in all copies or substantial portions of the Software.
|
| 15 |
+
#
|
| 16 |
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
| 17 |
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
| 18 |
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
| 19 |
+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
| 20 |
+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
| 21 |
+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
| 22 |
+
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
| 23 |
+
#
|
| 24 |
+
|
| 25 |
+
__doc__ = """
|
| 26 |
+
pyparsing module - Classes and methods to define and execute parsing grammars
|
| 27 |
+
=============================================================================
|
| 28 |
+
|
| 29 |
+
The pyparsing module is an alternative approach to creating and
|
| 30 |
+
executing simple grammars, vs. the traditional lex/yacc approach, or the
|
| 31 |
+
use of regular expressions. With pyparsing, you don't need to learn
|
| 32 |
+
a new syntax for defining grammars or matching expressions - the parsing
|
| 33 |
+
module provides a library of classes that you use to construct the
|
| 34 |
+
grammar directly in Python.
|
| 35 |
+
|
| 36 |
+
Here is a program to parse "Hello, World!" (or any greeting of the form
|
| 37 |
+
``"<salutation>, <addressee>!"``), built up using :class:`Word`,
|
| 38 |
+
:class:`Literal`, and :class:`And` elements
|
| 39 |
+
(the :meth:`'+'<ParserElement.__add__>` operators create :class:`And` expressions,
|
| 40 |
+
and the strings are auto-converted to :class:`Literal` expressions)::
|
| 41 |
+
|
| 42 |
+
from pyparsing import Word, alphas
|
| 43 |
+
|
| 44 |
+
# define grammar of a greeting
|
| 45 |
+
greet = Word(alphas) + "," + Word(alphas) + "!"
|
| 46 |
+
|
| 47 |
+
hello = "Hello, World!"
|
| 48 |
+
print(hello, "->", greet.parse_string(hello))
|
| 49 |
+
|
| 50 |
+
The program outputs the following::
|
| 51 |
+
|
| 52 |
+
Hello, World! -> ['Hello', ',', 'World', '!']
|
| 53 |
+
|
| 54 |
+
The Python representation of the grammar is quite readable, owing to the
|
| 55 |
+
self-explanatory class names, and the use of :class:`'+'<And>`,
|
| 56 |
+
:class:`'|'<MatchFirst>`, :class:`'^'<Or>` and :class:`'&'<Each>` operators.
|
| 57 |
+
|
| 58 |
+
The :class:`ParseResults` object returned from
|
| 59 |
+
:class:`ParserElement.parse_string` can be
|
| 60 |
+
accessed as a nested list, a dictionary, or an object with named
|
| 61 |
+
attributes.
|
| 62 |
+
|
| 63 |
+
The pyparsing module handles some of the problems that are typically
|
| 64 |
+
vexing when writing text parsers:
|
| 65 |
+
|
| 66 |
+
- extra or missing whitespace (the above program will also handle
|
| 67 |
+
"Hello,World!", "Hello , World !", etc.)
|
| 68 |
+
- quoted strings
|
| 69 |
+
- embedded comments
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
Getting Started -
|
| 73 |
+
-----------------
|
| 74 |
+
Visit the classes :class:`ParserElement` and :class:`ParseResults` to
|
| 75 |
+
see the base classes that most other pyparsing
|
| 76 |
+
classes inherit from. Use the docstrings for examples of how to:
|
| 77 |
+
|
| 78 |
+
- construct literal match expressions from :class:`Literal` and
|
| 79 |
+
:class:`CaselessLiteral` classes
|
| 80 |
+
- construct character word-group expressions using the :class:`Word`
|
| 81 |
+
class
|
| 82 |
+
- see how to create repetitive expressions using :class:`ZeroOrMore`
|
| 83 |
+
and :class:`OneOrMore` classes
|
| 84 |
+
- use :class:`'+'<And>`, :class:`'|'<MatchFirst>`, :class:`'^'<Or>`,
|
| 85 |
+
and :class:`'&'<Each>` operators to combine simple expressions into
|
| 86 |
+
more complex ones
|
| 87 |
+
- associate names with your parsed results using
|
| 88 |
+
:class:`ParserElement.set_results_name`
|
| 89 |
+
- access the parsed data, which is returned as a :class:`ParseResults`
|
| 90 |
+
object
|
| 91 |
+
- find some helpful expression short-cuts like :class:`DelimitedList`
|
| 92 |
+
and :class:`one_of`
|
| 93 |
+
- find more useful common expressions in the :class:`pyparsing_common`
|
| 94 |
+
namespace class
|
| 95 |
+
"""
|
| 96 |
+
from typing import NamedTuple
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
class version_info(NamedTuple):
|
| 100 |
+
major: int
|
| 101 |
+
minor: int
|
| 102 |
+
micro: int
|
| 103 |
+
releaselevel: str
|
| 104 |
+
serial: int
|
| 105 |
+
|
| 106 |
+
@property
|
| 107 |
+
def __version__(self):
|
| 108 |
+
return (
|
| 109 |
+
f"{self.major}.{self.minor}.{self.micro}"
|
| 110 |
+
+ (
|
| 111 |
+
f"{'r' if self.releaselevel[0] == 'c' else ''}{self.releaselevel[0]}{self.serial}",
|
| 112 |
+
"",
|
| 113 |
+
)[self.releaselevel == "final"]
|
| 114 |
+
)
|
| 115 |
+
|
| 116 |
+
def __str__(self):
|
| 117 |
+
return f"{__name__} {self.__version__} / {__version_time__}"
|
| 118 |
+
|
| 119 |
+
def __repr__(self):
|
| 120 |
+
return f"{__name__}.{type(self).__name__}({', '.join('{}={!r}'.format(*nv) for nv in zip(self._fields, self))})"
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
__version_info__ = version_info(3, 2, 0, "final", 1)
|
| 124 |
+
__version_time__ = "13 Oct 2024 09:46 UTC"
|
| 125 |
+
__version__ = __version_info__.__version__
|
| 126 |
+
__versionTime__ = __version_time__
|
| 127 |
+
__author__ = "Paul McGuire <ptmcg.gm+pyparsing@gmail.com>"
|
| 128 |
+
|
| 129 |
+
from .util import *
|
| 130 |
+
from .exceptions import *
|
| 131 |
+
from .actions import *
|
| 132 |
+
from .core import __diag__, __compat__
|
| 133 |
+
from .results import *
|
| 134 |
+
from .core import *
|
| 135 |
+
from .core import _builtin_exprs as core_builtin_exprs
|
| 136 |
+
from .helpers import *
|
| 137 |
+
from .helpers import _builtin_exprs as helper_builtin_exprs
|
| 138 |
+
|
| 139 |
+
from .unicode import unicode_set, UnicodeRangeList, pyparsing_unicode as unicode
|
| 140 |
+
from .testing import pyparsing_test as testing
|
| 141 |
+
from .common import (
|
| 142 |
+
pyparsing_common as common,
|
| 143 |
+
_builtin_exprs as common_builtin_exprs,
|
| 144 |
+
)
|
| 145 |
+
|
| 146 |
+
# Compatibility synonyms
|
| 147 |
+
if "pyparsing_unicode" not in globals():
|
| 148 |
+
pyparsing_unicode = unicode # type: ignore[misc]
|
| 149 |
+
if "pyparsing_common" not in globals():
|
| 150 |
+
pyparsing_common = common
|
| 151 |
+
if "pyparsing_test" not in globals():
|
| 152 |
+
pyparsing_test = testing
|
| 153 |
+
|
| 154 |
+
core_builtin_exprs += common_builtin_exprs + helper_builtin_exprs
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
__all__ = [
|
| 158 |
+
"__version__",
|
| 159 |
+
"__version_time__",
|
| 160 |
+
"__author__",
|
| 161 |
+
"__compat__",
|
| 162 |
+
"__diag__",
|
| 163 |
+
"And",
|
| 164 |
+
"AtLineStart",
|
| 165 |
+
"AtStringStart",
|
| 166 |
+
"CaselessKeyword",
|
| 167 |
+
"CaselessLiteral",
|
| 168 |
+
"CharsNotIn",
|
| 169 |
+
"CloseMatch",
|
| 170 |
+
"Combine",
|
| 171 |
+
"DelimitedList",
|
| 172 |
+
"Dict",
|
| 173 |
+
"Each",
|
| 174 |
+
"Empty",
|
| 175 |
+
"FollowedBy",
|
| 176 |
+
"Forward",
|
| 177 |
+
"GoToColumn",
|
| 178 |
+
"Group",
|
| 179 |
+
"IndentedBlock",
|
| 180 |
+
"Keyword",
|
| 181 |
+
"LineEnd",
|
| 182 |
+
"LineStart",
|
| 183 |
+
"Literal",
|
| 184 |
+
"Located",
|
| 185 |
+
"PrecededBy",
|
| 186 |
+
"MatchFirst",
|
| 187 |
+
"NoMatch",
|
| 188 |
+
"NotAny",
|
| 189 |
+
"OneOrMore",
|
| 190 |
+
"OnlyOnce",
|
| 191 |
+
"OpAssoc",
|
| 192 |
+
"Opt",
|
| 193 |
+
"Optional",
|
| 194 |
+
"Or",
|
| 195 |
+
"ParseBaseException",
|
| 196 |
+
"ParseElementEnhance",
|
| 197 |
+
"ParseException",
|
| 198 |
+
"ParseExpression",
|
| 199 |
+
"ParseFatalException",
|
| 200 |
+
"ParseResults",
|
| 201 |
+
"ParseSyntaxException",
|
| 202 |
+
"ParserElement",
|
| 203 |
+
"PositionToken",
|
| 204 |
+
"QuotedString",
|
| 205 |
+
"RecursiveGrammarException",
|
| 206 |
+
"Regex",
|
| 207 |
+
"SkipTo",
|
| 208 |
+
"StringEnd",
|
| 209 |
+
"StringStart",
|
| 210 |
+
"Suppress",
|
| 211 |
+
"Tag",
|
| 212 |
+
"Token",
|
| 213 |
+
"TokenConverter",
|
| 214 |
+
"White",
|
| 215 |
+
"Word",
|
| 216 |
+
"WordEnd",
|
| 217 |
+
"WordStart",
|
| 218 |
+
"ZeroOrMore",
|
| 219 |
+
"Char",
|
| 220 |
+
"alphanums",
|
| 221 |
+
"alphas",
|
| 222 |
+
"alphas8bit",
|
| 223 |
+
"any_close_tag",
|
| 224 |
+
"any_open_tag",
|
| 225 |
+
"autoname_elements",
|
| 226 |
+
"c_style_comment",
|
| 227 |
+
"col",
|
| 228 |
+
"common_html_entity",
|
| 229 |
+
"condition_as_parse_action",
|
| 230 |
+
"counted_array",
|
| 231 |
+
"cpp_style_comment",
|
| 232 |
+
"dbl_quoted_string",
|
| 233 |
+
"dbl_slash_comment",
|
| 234 |
+
"delimited_list",
|
| 235 |
+
"dict_of",
|
| 236 |
+
"empty",
|
| 237 |
+
"hexnums",
|
| 238 |
+
"html_comment",
|
| 239 |
+
"identchars",
|
| 240 |
+
"identbodychars",
|
| 241 |
+
"infix_notation",
|
| 242 |
+
"java_style_comment",
|
| 243 |
+
"line",
|
| 244 |
+
"line_end",
|
| 245 |
+
"line_start",
|
| 246 |
+
"lineno",
|
| 247 |
+
"make_html_tags",
|
| 248 |
+
"make_xml_tags",
|
| 249 |
+
"match_only_at_col",
|
| 250 |
+
"match_previous_expr",
|
| 251 |
+
"match_previous_literal",
|
| 252 |
+
"nested_expr",
|
| 253 |
+
"null_debug_action",
|
| 254 |
+
"nums",
|
| 255 |
+
"one_of",
|
| 256 |
+
"original_text_for",
|
| 257 |
+
"printables",
|
| 258 |
+
"punc8bit",
|
| 259 |
+
"pyparsing_common",
|
| 260 |
+
"pyparsing_test",
|
| 261 |
+
"pyparsing_unicode",
|
| 262 |
+
"python_style_comment",
|
| 263 |
+
"quoted_string",
|
| 264 |
+
"remove_quotes",
|
| 265 |
+
"replace_with",
|
| 266 |
+
"replace_html_entity",
|
| 267 |
+
"rest_of_line",
|
| 268 |
+
"sgl_quoted_string",
|
| 269 |
+
"srange",
|
| 270 |
+
"string_end",
|
| 271 |
+
"string_start",
|
| 272 |
+
"token_map",
|
| 273 |
+
"trace_parse_action",
|
| 274 |
+
"ungroup",
|
| 275 |
+
"unicode_set",
|
| 276 |
+
"unicode_string",
|
| 277 |
+
"with_attribute",
|
| 278 |
+
"with_class",
|
| 279 |
+
# pre-PEP8 compatibility names
|
| 280 |
+
"__versionTime__",
|
| 281 |
+
"anyCloseTag",
|
| 282 |
+
"anyOpenTag",
|
| 283 |
+
"cStyleComment",
|
| 284 |
+
"commonHTMLEntity",
|
| 285 |
+
"conditionAsParseAction",
|
| 286 |
+
"countedArray",
|
| 287 |
+
"cppStyleComment",
|
| 288 |
+
"dblQuotedString",
|
| 289 |
+
"dblSlashComment",
|
| 290 |
+
"delimitedList",
|
| 291 |
+
"dictOf",
|
| 292 |
+
"htmlComment",
|
| 293 |
+
"indentedBlock",
|
| 294 |
+
"infixNotation",
|
| 295 |
+
"javaStyleComment",
|
| 296 |
+
"lineEnd",
|
| 297 |
+
"lineStart",
|
| 298 |
+
"locatedExpr",
|
| 299 |
+
"makeHTMLTags",
|
| 300 |
+
"makeXMLTags",
|
| 301 |
+
"matchOnlyAtCol",
|
| 302 |
+
"matchPreviousExpr",
|
| 303 |
+
"matchPreviousLiteral",
|
| 304 |
+
"nestedExpr",
|
| 305 |
+
"nullDebugAction",
|
| 306 |
+
"oneOf",
|
| 307 |
+
"opAssoc",
|
| 308 |
+
"originalTextFor",
|
| 309 |
+
"pythonStyleComment",
|
| 310 |
+
"quotedString",
|
| 311 |
+
"removeQuotes",
|
| 312 |
+
"replaceHTMLEntity",
|
| 313 |
+
"replaceWith",
|
| 314 |
+
"restOfLine",
|
| 315 |
+
"sglQuotedString",
|
| 316 |
+
"stringEnd",
|
| 317 |
+
"stringStart",
|
| 318 |
+
"tokenMap",
|
| 319 |
+
"traceParseAction",
|
| 320 |
+
"unicodeString",
|
| 321 |
+
"withAttribute",
|
| 322 |
+
"withClass",
|
| 323 |
+
"common",
|
| 324 |
+
"unicode",
|
| 325 |
+
"testing",
|
| 326 |
+
]
|
llava_next/lib/python3.10/site-packages/pyparsing/actions.py
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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only called once.
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
def __init__(self, method_call):
|
| 13 |
+
from .core import _trim_arity
|
| 14 |
+
|
| 15 |
+
self.callable = _trim_arity(method_call)
|
| 16 |
+
self.called = False
|
| 17 |
+
|
| 18 |
+
def __call__(self, s, l, t):
|
| 19 |
+
if not self.called:
|
| 20 |
+
results = self.callable(s, l, t)
|
| 21 |
+
self.called = True
|
| 22 |
+
return results
|
| 23 |
+
raise ParseException(s, l, "OnlyOnce obj called multiple times w/out reset")
|
| 24 |
+
|
| 25 |
+
def reset(self):
|
| 26 |
+
"""
|
| 27 |
+
Allow the associated parse action to be called once more.
|
| 28 |
+
"""
|
| 29 |
+
|
| 30 |
+
self.called = False
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def match_only_at_col(n):
|
| 34 |
+
"""
|
| 35 |
+
Helper method for defining parse actions that require matching at
|
| 36 |
+
a specific column in the input text.
|
| 37 |
+
"""
|
| 38 |
+
|
| 39 |
+
def verify_col(strg, locn, toks):
|
| 40 |
+
if col(locn, strg) != n:
|
| 41 |
+
raise ParseException(strg, locn, f"matched token not at column {n}")
|
| 42 |
+
|
| 43 |
+
return verify_col
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def replace_with(repl_str):
|
| 47 |
+
"""
|
| 48 |
+
Helper method for common parse actions that simply return
|
| 49 |
+
a literal value. Especially useful when used with
|
| 50 |
+
:class:`transform_string<ParserElement.transform_string>` ().
|
| 51 |
+
|
| 52 |
+
Example::
|
| 53 |
+
|
| 54 |
+
num = Word(nums).set_parse_action(lambda toks: int(toks[0]))
|
| 55 |
+
na = one_of("N/A NA").set_parse_action(replace_with(math.nan))
|
| 56 |
+
term = na | num
|
| 57 |
+
|
| 58 |
+
term[1, ...].parse_string("324 234 N/A 234") # -> [324, 234, nan, 234]
|
| 59 |
+
"""
|
| 60 |
+
return lambda s, l, t: [repl_str]
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def remove_quotes(s, l, t):
|
| 64 |
+
"""
|
| 65 |
+
Helper parse action for removing quotation marks from parsed
|
| 66 |
+
quoted strings.
|
| 67 |
+
|
| 68 |
+
Example::
|
| 69 |
+
|
| 70 |
+
# by default, quotation marks are included in parsed results
|
| 71 |
+
quoted_string.parse_string("'Now is the Winter of our Discontent'") # -> ["'Now is the Winter of our Discontent'"]
|
| 72 |
+
|
| 73 |
+
# use remove_quotes to strip quotation marks from parsed results
|
| 74 |
+
quoted_string.set_parse_action(remove_quotes)
|
| 75 |
+
quoted_string.parse_string("'Now is the Winter of our Discontent'") # -> ["Now is the Winter of our Discontent"]
|
| 76 |
+
"""
|
| 77 |
+
return t[0][1:-1]
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def with_attribute(*args, **attr_dict):
|
| 81 |
+
"""
|
| 82 |
+
Helper to create a validating parse action to be used with start
|
| 83 |
+
tags created with :class:`make_xml_tags` or
|
| 84 |
+
:class:`make_html_tags`. Use ``with_attribute`` to qualify
|
| 85 |
+
a starting tag with a required attribute value, to avoid false
|
| 86 |
+
matches on common tags such as ``<TD>`` or ``<DIV>``.
|
| 87 |
+
|
| 88 |
+
Call ``with_attribute`` with a series of attribute names and
|
| 89 |
+
values. Specify the list of filter attributes names and values as:
|
| 90 |
+
|
| 91 |
+
- keyword arguments, as in ``(align="right")``, or
|
| 92 |
+
- as an explicit dict with ``**`` operator, when an attribute
|
| 93 |
+
name is also a Python reserved word, as in ``**{"class":"Customer", "align":"right"}``
|
| 94 |
+
- a list of name-value tuples, as in ``(("ns1:class", "Customer"), ("ns2:align", "right"))``
|
| 95 |
+
|
| 96 |
+
For attribute names with a namespace prefix, you must use the second
|
| 97 |
+
form. Attribute names are matched insensitive to upper/lower case.
|
| 98 |
+
|
| 99 |
+
If just testing for ``class`` (with or without a namespace), use
|
| 100 |
+
:class:`with_class`.
|
| 101 |
+
|
| 102 |
+
To verify that the attribute exists, but without specifying a value,
|
| 103 |
+
pass ``with_attribute.ANY_VALUE`` as the value.
|
| 104 |
+
|
| 105 |
+
Example::
|
| 106 |
+
|
| 107 |
+
html = '''
|
| 108 |
+
<div>
|
| 109 |
+
Some text
|
| 110 |
+
<div type="grid">1 4 0 1 0</div>
|
| 111 |
+
<div type="graph">1,3 2,3 1,1</div>
|
| 112 |
+
<div>this has no type</div>
|
| 113 |
+
</div>
|
| 114 |
+
'''
|
| 115 |
+
div,div_end = make_html_tags("div")
|
| 116 |
+
|
| 117 |
+
# only match div tag having a type attribute with value "grid"
|
| 118 |
+
div_grid = div().set_parse_action(with_attribute(type="grid"))
|
| 119 |
+
grid_expr = div_grid + SkipTo(div | div_end)("body")
|
| 120 |
+
for grid_header in grid_expr.search_string(html):
|
| 121 |
+
print(grid_header.body)
|
| 122 |
+
|
| 123 |
+
# construct a match with any div tag having a type attribute, regardless of the value
|
| 124 |
+
div_any_type = div().set_parse_action(with_attribute(type=with_attribute.ANY_VALUE))
|
| 125 |
+
div_expr = div_any_type + SkipTo(div | div_end)("body")
|
| 126 |
+
for div_header in div_expr.search_string(html):
|
| 127 |
+
print(div_header.body)
|
| 128 |
+
|
| 129 |
+
prints::
|
| 130 |
+
|
| 131 |
+
1 4 0 1 0
|
| 132 |
+
|
| 133 |
+
1 4 0 1 0
|
| 134 |
+
1,3 2,3 1,1
|
| 135 |
+
"""
|
| 136 |
+
if args:
|
| 137 |
+
attrs = args[:]
|
| 138 |
+
else:
|
| 139 |
+
attrs = attr_dict.items()
|
| 140 |
+
attrs = [(k, v) for k, v in attrs]
|
| 141 |
+
|
| 142 |
+
def pa(s, l, tokens):
|
| 143 |
+
for attrName, attrValue in attrs:
|
| 144 |
+
if attrName not in tokens:
|
| 145 |
+
raise ParseException(s, l, "no matching attribute " + attrName)
|
| 146 |
+
if attrValue != with_attribute.ANY_VALUE and tokens[attrName] != attrValue:
|
| 147 |
+
raise ParseException(
|
| 148 |
+
s,
|
| 149 |
+
l,
|
| 150 |
+
f"attribute {attrName!r} has value {tokens[attrName]!r}, must be {attrValue!r}",
|
| 151 |
+
)
|
| 152 |
+
|
| 153 |
+
return pa
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
with_attribute.ANY_VALUE = object() # type: ignore [attr-defined]
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
def with_class(classname, namespace=""):
|
| 160 |
+
"""
|
| 161 |
+
Simplified version of :class:`with_attribute` when
|
| 162 |
+
matching on a div class - made difficult because ``class`` is
|
| 163 |
+
a reserved word in Python.
|
| 164 |
+
|
| 165 |
+
Example::
|
| 166 |
+
|
| 167 |
+
html = '''
|
| 168 |
+
<div>
|
| 169 |
+
Some text
|
| 170 |
+
<div class="grid">1 4 0 1 0</div>
|
| 171 |
+
<div class="graph">1,3 2,3 1,1</div>
|
| 172 |
+
<div>this <div> has no class</div>
|
| 173 |
+
</div>
|
| 174 |
+
|
| 175 |
+
'''
|
| 176 |
+
div,div_end = make_html_tags("div")
|
| 177 |
+
div_grid = div().set_parse_action(with_class("grid"))
|
| 178 |
+
|
| 179 |
+
grid_expr = div_grid + SkipTo(div | div_end)("body")
|
| 180 |
+
for grid_header in grid_expr.search_string(html):
|
| 181 |
+
print(grid_header.body)
|
| 182 |
+
|
| 183 |
+
div_any_type = div().set_parse_action(with_class(withAttribute.ANY_VALUE))
|
| 184 |
+
div_expr = div_any_type + SkipTo(div | div_end)("body")
|
| 185 |
+
for div_header in div_expr.search_string(html):
|
| 186 |
+
print(div_header.body)
|
| 187 |
+
|
| 188 |
+
prints::
|
| 189 |
+
|
| 190 |
+
1 4 0 1 0
|
| 191 |
+
|
| 192 |
+
1 4 0 1 0
|
| 193 |
+
1,3 2,3 1,1
|
| 194 |
+
"""
|
| 195 |
+
classattr = f"{namespace}:class" if namespace else "class"
|
| 196 |
+
return with_attribute(**{classattr: classname})
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
# Compatibility synonyms
|
| 200 |
+
# fmt: off
|
| 201 |
+
replaceWith = replaced_by_pep8("replaceWith", replace_with)
|
| 202 |
+
removeQuotes = replaced_by_pep8("removeQuotes", remove_quotes)
|
| 203 |
+
withAttribute = replaced_by_pep8("withAttribute", with_attribute)
|
| 204 |
+
withClass = replaced_by_pep8("withClass", with_class)
|
| 205 |
+
matchOnlyAtCol = replaced_by_pep8("matchOnlyAtCol", match_only_at_col)
|
| 206 |
+
# fmt: on
|
llava_next/lib/python3.10/site-packages/pyparsing/exceptions.py
ADDED
|
@@ -0,0 +1,314 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# exceptions.py
|
| 2 |
+
from __future__ import annotations
|
| 3 |
+
|
| 4 |
+
import copy
|
| 5 |
+
import re
|
| 6 |
+
import sys
|
| 7 |
+
import typing
|
| 8 |
+
from functools import cached_property
|
| 9 |
+
|
| 10 |
+
from .unicode import pyparsing_unicode as ppu
|
| 11 |
+
from .util import (
|
| 12 |
+
_collapse_string_to_ranges,
|
| 13 |
+
col,
|
| 14 |
+
line,
|
| 15 |
+
lineno,
|
| 16 |
+
replaced_by_pep8,
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class _ExceptionWordUnicodeSet(
|
| 21 |
+
ppu.Latin1, ppu.LatinA, ppu.LatinB, ppu.Greek, ppu.Cyrillic
|
| 22 |
+
):
|
| 23 |
+
pass
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
_extract_alphanums = _collapse_string_to_ranges(_ExceptionWordUnicodeSet.alphanums)
|
| 27 |
+
_exception_word_extractor = re.compile("([" + _extract_alphanums + "]{1,16})|.")
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
class ParseBaseException(Exception):
|
| 31 |
+
"""base exception class for all parsing runtime exceptions"""
|
| 32 |
+
|
| 33 |
+
loc: int
|
| 34 |
+
msg: str
|
| 35 |
+
pstr: str
|
| 36 |
+
parser_element: typing.Any # "ParserElement"
|
| 37 |
+
args: tuple[str, int, typing.Optional[str]]
|
| 38 |
+
|
| 39 |
+
__slots__ = (
|
| 40 |
+
"loc",
|
| 41 |
+
"msg",
|
| 42 |
+
"pstr",
|
| 43 |
+
"parser_element",
|
| 44 |
+
"args",
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
# Performance tuning: we construct a *lot* of these, so keep this
|
| 48 |
+
# constructor as small and fast as possible
|
| 49 |
+
def __init__(
|
| 50 |
+
self,
|
| 51 |
+
pstr: str,
|
| 52 |
+
loc: int = 0,
|
| 53 |
+
msg: typing.Optional[str] = None,
|
| 54 |
+
elem=None,
|
| 55 |
+
):
|
| 56 |
+
if msg is None:
|
| 57 |
+
msg, pstr = pstr, ""
|
| 58 |
+
|
| 59 |
+
self.loc = loc
|
| 60 |
+
self.msg = msg
|
| 61 |
+
self.pstr = pstr
|
| 62 |
+
self.parser_element = elem
|
| 63 |
+
self.args = (pstr, loc, msg)
|
| 64 |
+
|
| 65 |
+
@staticmethod
|
| 66 |
+
def explain_exception(exc: Exception, depth: int = 16) -> str:
|
| 67 |
+
"""
|
| 68 |
+
Method to take an exception and translate the Python internal traceback into a list
|
| 69 |
+
of the pyparsing expressions that caused the exception to be raised.
|
| 70 |
+
|
| 71 |
+
Parameters:
|
| 72 |
+
|
| 73 |
+
- exc - exception raised during parsing (need not be a ParseException, in support
|
| 74 |
+
of Python exceptions that might be raised in a parse action)
|
| 75 |
+
- depth (default=16) - number of levels back in the stack trace to list expression
|
| 76 |
+
and function names; if None, the full stack trace names will be listed; if 0, only
|
| 77 |
+
the failing input line, marker, and exception string will be shown
|
| 78 |
+
|
| 79 |
+
Returns a multi-line string listing the ParserElements and/or function names in the
|
| 80 |
+
exception's stack trace.
|
| 81 |
+
"""
|
| 82 |
+
import inspect
|
| 83 |
+
from .core import ParserElement
|
| 84 |
+
|
| 85 |
+
if depth is None:
|
| 86 |
+
depth = sys.getrecursionlimit()
|
| 87 |
+
ret: list[str] = []
|
| 88 |
+
if isinstance(exc, ParseBaseException):
|
| 89 |
+
ret.append(exc.line)
|
| 90 |
+
ret.append(f"{' ' * (exc.column - 1)}^")
|
| 91 |
+
ret.append(f"{type(exc).__name__}: {exc}")
|
| 92 |
+
|
| 93 |
+
if depth <= 0 or exc.__traceback__ is None:
|
| 94 |
+
return "\n".join(ret)
|
| 95 |
+
|
| 96 |
+
callers = inspect.getinnerframes(exc.__traceback__, context=depth)
|
| 97 |
+
seen: set[int] = set()
|
| 98 |
+
for ff in callers[-depth:]:
|
| 99 |
+
frm = ff[0]
|
| 100 |
+
|
| 101 |
+
f_self = frm.f_locals.get("self", None)
|
| 102 |
+
if isinstance(f_self, ParserElement):
|
| 103 |
+
if not frm.f_code.co_name.startswith(("parseImpl", "_parseNoCache")):
|
| 104 |
+
continue
|
| 105 |
+
if id(f_self) in seen:
|
| 106 |
+
continue
|
| 107 |
+
seen.add(id(f_self))
|
| 108 |
+
|
| 109 |
+
self_type = type(f_self)
|
| 110 |
+
ret.append(f"{self_type.__module__}.{self_type.__name__} - {f_self}")
|
| 111 |
+
|
| 112 |
+
elif f_self is not None:
|
| 113 |
+
self_type = type(f_self)
|
| 114 |
+
ret.append(f"{self_type.__module__}.{self_type.__name__}")
|
| 115 |
+
|
| 116 |
+
else:
|
| 117 |
+
code = frm.f_code
|
| 118 |
+
if code.co_name in ("wrapper", "<module>"):
|
| 119 |
+
continue
|
| 120 |
+
|
| 121 |
+
ret.append(code.co_name)
|
| 122 |
+
|
| 123 |
+
depth -= 1
|
| 124 |
+
if not depth:
|
| 125 |
+
break
|
| 126 |
+
|
| 127 |
+
return "\n".join(ret)
|
| 128 |
+
|
| 129 |
+
@classmethod
|
| 130 |
+
def _from_exception(cls, pe) -> ParseBaseException:
|
| 131 |
+
"""
|
| 132 |
+
internal factory method to simplify creating one type of ParseException
|
| 133 |
+
from another - avoids having __init__ signature conflicts among subclasses
|
| 134 |
+
"""
|
| 135 |
+
return cls(pe.pstr, pe.loc, pe.msg, pe.parser_element)
|
| 136 |
+
|
| 137 |
+
@cached_property
|
| 138 |
+
def line(self) -> str:
|
| 139 |
+
"""
|
| 140 |
+
Return the line of text where the exception occurred.
|
| 141 |
+
"""
|
| 142 |
+
return line(self.loc, self.pstr)
|
| 143 |
+
|
| 144 |
+
@cached_property
|
| 145 |
+
def lineno(self) -> int:
|
| 146 |
+
"""
|
| 147 |
+
Return the 1-based line number of text where the exception occurred.
|
| 148 |
+
"""
|
| 149 |
+
return lineno(self.loc, self.pstr)
|
| 150 |
+
|
| 151 |
+
@cached_property
|
| 152 |
+
def col(self) -> int:
|
| 153 |
+
"""
|
| 154 |
+
Return the 1-based column on the line of text where the exception occurred.
|
| 155 |
+
"""
|
| 156 |
+
return col(self.loc, self.pstr)
|
| 157 |
+
|
| 158 |
+
@cached_property
|
| 159 |
+
def column(self) -> int:
|
| 160 |
+
"""
|
| 161 |
+
Return the 1-based column on the line of text where the exception occurred.
|
| 162 |
+
"""
|
| 163 |
+
return col(self.loc, self.pstr)
|
| 164 |
+
|
| 165 |
+
@cached_property
|
| 166 |
+
def found(self) -> str:
|
| 167 |
+
if not self.pstr:
|
| 168 |
+
return ""
|
| 169 |
+
|
| 170 |
+
if self.loc >= len(self.pstr):
|
| 171 |
+
return "end of text"
|
| 172 |
+
|
| 173 |
+
# pull out next word at error location
|
| 174 |
+
found_match = _exception_word_extractor.match(self.pstr, self.loc)
|
| 175 |
+
if found_match is not None:
|
| 176 |
+
found_text = found_match.group(0)
|
| 177 |
+
else:
|
| 178 |
+
found_text = self.pstr[self.loc : self.loc + 1]
|
| 179 |
+
|
| 180 |
+
return repr(found_text).replace(r"\\", "\\")
|
| 181 |
+
|
| 182 |
+
# pre-PEP8 compatibility
|
| 183 |
+
@property
|
| 184 |
+
def parserElement(self):
|
| 185 |
+
return self.parser_element
|
| 186 |
+
|
| 187 |
+
@parserElement.setter
|
| 188 |
+
def parserElement(self, elem):
|
| 189 |
+
self.parser_element = elem
|
| 190 |
+
|
| 191 |
+
def copy(self):
|
| 192 |
+
return copy.copy(self)
|
| 193 |
+
|
| 194 |
+
def formatted_message(self) -> str:
|
| 195 |
+
found_phrase = f", found {self.found}" if self.found else ""
|
| 196 |
+
return f"{self.msg}{found_phrase} (at char {self.loc}), (line:{self.lineno}, col:{self.column})"
|
| 197 |
+
|
| 198 |
+
def __str__(self) -> str:
|
| 199 |
+
return self.formatted_message()
|
| 200 |
+
|
| 201 |
+
def __repr__(self):
|
| 202 |
+
return str(self)
|
| 203 |
+
|
| 204 |
+
def mark_input_line(
|
| 205 |
+
self, marker_string: typing.Optional[str] = None, *, markerString: str = ">!<"
|
| 206 |
+
) -> str:
|
| 207 |
+
"""
|
| 208 |
+
Extracts the exception line from the input string, and marks
|
| 209 |
+
the location of the exception with a special symbol.
|
| 210 |
+
"""
|
| 211 |
+
markerString = marker_string if marker_string is not None else markerString
|
| 212 |
+
line_str = self.line
|
| 213 |
+
line_column = self.column - 1
|
| 214 |
+
if markerString:
|
| 215 |
+
line_str = f"{line_str[:line_column]}{markerString}{line_str[line_column:]}"
|
| 216 |
+
return line_str.strip()
|
| 217 |
+
|
| 218 |
+
def explain(self, depth: int = 16) -> str:
|
| 219 |
+
"""
|
| 220 |
+
Method to translate the Python internal traceback into a list
|
| 221 |
+
of the pyparsing expressions that caused the exception to be raised.
|
| 222 |
+
|
| 223 |
+
Parameters:
|
| 224 |
+
|
| 225 |
+
- depth (default=16) - number of levels back in the stack trace to list expression
|
| 226 |
+
and function names; if None, the full stack trace names will be listed; if 0, only
|
| 227 |
+
the failing input line, marker, and exception string will be shown
|
| 228 |
+
|
| 229 |
+
Returns a multi-line string listing the ParserElements and/or function names in the
|
| 230 |
+
exception's stack trace.
|
| 231 |
+
|
| 232 |
+
Example::
|
| 233 |
+
|
| 234 |
+
# an expression to parse 3 integers
|
| 235 |
+
expr = pp.Word(pp.nums) * 3
|
| 236 |
+
try:
|
| 237 |
+
# a failing parse - the third integer is prefixed with "A"
|
| 238 |
+
expr.parse_string("123 456 A789")
|
| 239 |
+
except pp.ParseException as pe:
|
| 240 |
+
print(pe.explain(depth=0))
|
| 241 |
+
|
| 242 |
+
prints::
|
| 243 |
+
|
| 244 |
+
123 456 A789
|
| 245 |
+
^
|
| 246 |
+
ParseException: Expected W:(0-9), found 'A' (at char 8), (line:1, col:9)
|
| 247 |
+
|
| 248 |
+
Note: the diagnostic output will include string representations of the expressions
|
| 249 |
+
that failed to parse. These representations will be more helpful if you use `set_name` to
|
| 250 |
+
give identifiable names to your expressions. Otherwise they will use the default string
|
| 251 |
+
forms, which may be cryptic to read.
|
| 252 |
+
|
| 253 |
+
Note: pyparsing's default truncation of exception tracebacks may also truncate the
|
| 254 |
+
stack of expressions that are displayed in the ``explain`` output. To get the full listing
|
| 255 |
+
of parser expressions, you may have to set ``ParserElement.verbose_stacktrace = True``
|
| 256 |
+
"""
|
| 257 |
+
return self.explain_exception(self, depth)
|
| 258 |
+
|
| 259 |
+
# Compatibility synonyms
|
| 260 |
+
# fmt: off
|
| 261 |
+
markInputline = replaced_by_pep8("markInputline", mark_input_line)
|
| 262 |
+
# fmt: on
|
| 263 |
+
|
| 264 |
+
|
| 265 |
+
class ParseException(ParseBaseException):
|
| 266 |
+
"""
|
| 267 |
+
Exception thrown when a parse expression doesn't match the input string
|
| 268 |
+
|
| 269 |
+
Example::
|
| 270 |
+
|
| 271 |
+
integer = Word(nums).set_name("integer")
|
| 272 |
+
try:
|
| 273 |
+
integer.parse_string("ABC")
|
| 274 |
+
except ParseException as pe:
|
| 275 |
+
print(pe)
|
| 276 |
+
print(f"column: {pe.column}")
|
| 277 |
+
|
| 278 |
+
prints::
|
| 279 |
+
|
| 280 |
+
Expected integer (at char 0), (line:1, col:1) column: 1
|
| 281 |
+
|
| 282 |
+
"""
|
| 283 |
+
|
| 284 |
+
|
| 285 |
+
class ParseFatalException(ParseBaseException):
|
| 286 |
+
"""
|
| 287 |
+
User-throwable exception thrown when inconsistent parse content
|
| 288 |
+
is found; stops all parsing immediately
|
| 289 |
+
"""
|
| 290 |
+
|
| 291 |
+
|
| 292 |
+
class ParseSyntaxException(ParseFatalException):
|
| 293 |
+
"""
|
| 294 |
+
Just like :class:`ParseFatalException`, but thrown internally
|
| 295 |
+
when an :class:`ErrorStop<And._ErrorStop>` ('-' operator) indicates
|
| 296 |
+
that parsing is to stop immediately because an unbacktrackable
|
| 297 |
+
syntax error has been found.
|
| 298 |
+
"""
|
| 299 |
+
|
| 300 |
+
|
| 301 |
+
class RecursiveGrammarException(Exception):
|
| 302 |
+
"""
|
| 303 |
+
Exception thrown by :class:`ParserElement.validate` if the
|
| 304 |
+
grammar could be left-recursive; parser may need to enable
|
| 305 |
+
left recursion using :class:`ParserElement.enable_left_recursion<ParserElement.enable_left_recursion>`
|
| 306 |
+
|
| 307 |
+
Deprecated: only used by deprecated method ParserElement.validate.
|
| 308 |
+
"""
|
| 309 |
+
|
| 310 |
+
def __init__(self, parseElementList):
|
| 311 |
+
self.parseElementTrace = parseElementList
|
| 312 |
+
|
| 313 |
+
def __str__(self) -> str:
|
| 314 |
+
return f"RecursiveGrammarException: {self.parseElementTrace}"
|
llava_next/lib/python3.10/site-packages/sniffio/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (420 Bytes). View file
|
|
|
llava_next/lib/python3.10/site-packages/sniffio/__pycache__/_impl.cpython-310.pyc
ADDED
|
Binary file (2.66 kB). View file
|
|
|
llava_next/lib/python3.10/site-packages/sniffio/__pycache__/_version.cpython-310.pyc
ADDED
|
Binary file (184 Bytes). View file
|
|
|
llava_next/lib/python3.10/site-packages/sniffio/_tests/__init__.py
ADDED
|
File without changes
|
llava_next/lib/python3.10/site-packages/sniffio/_tests/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (170 Bytes). View file
|
|
|
llava_next/lib/python3.10/site-packages/sniffio/_tests/__pycache__/test_sniffio.cpython-310.pyc
ADDED
|
Binary file (2.11 kB). View file
|
|
|
llava_next/lib/python3.10/site-packages/sniffio/_tests/test_sniffio.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
|
| 4 |
+
import pytest
|
| 5 |
+
|
| 6 |
+
from .. import (
|
| 7 |
+
current_async_library, AsyncLibraryNotFoundError,
|
| 8 |
+
current_async_library_cvar, thread_local
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def test_basics_cvar():
|
| 13 |
+
with pytest.raises(AsyncLibraryNotFoundError):
|
| 14 |
+
current_async_library()
|
| 15 |
+
|
| 16 |
+
token = current_async_library_cvar.set("generic-lib")
|
| 17 |
+
try:
|
| 18 |
+
assert current_async_library() == "generic-lib"
|
| 19 |
+
finally:
|
| 20 |
+
current_async_library_cvar.reset(token)
|
| 21 |
+
|
| 22 |
+
with pytest.raises(AsyncLibraryNotFoundError):
|
| 23 |
+
current_async_library()
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def test_basics_tlocal():
|
| 27 |
+
with pytest.raises(AsyncLibraryNotFoundError):
|
| 28 |
+
current_async_library()
|
| 29 |
+
|
| 30 |
+
old_name, thread_local.name = thread_local.name, "generic-lib"
|
| 31 |
+
try:
|
| 32 |
+
assert current_async_library() == "generic-lib"
|
| 33 |
+
finally:
|
| 34 |
+
thread_local.name = old_name
|
| 35 |
+
|
| 36 |
+
with pytest.raises(AsyncLibraryNotFoundError):
|
| 37 |
+
current_async_library()
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def test_asyncio():
|
| 41 |
+
import asyncio
|
| 42 |
+
|
| 43 |
+
with pytest.raises(AsyncLibraryNotFoundError):
|
| 44 |
+
current_async_library()
|
| 45 |
+
|
| 46 |
+
ran = []
|
| 47 |
+
|
| 48 |
+
async def this_is_asyncio():
|
| 49 |
+
assert current_async_library() == "asyncio"
|
| 50 |
+
# Call it a second time to exercise the caching logic
|
| 51 |
+
assert current_async_library() == "asyncio"
|
| 52 |
+
ran.append(True)
|
| 53 |
+
|
| 54 |
+
asyncio.run(this_is_asyncio())
|
| 55 |
+
assert ran == [True]
|
| 56 |
+
|
| 57 |
+
with pytest.raises(AsyncLibraryNotFoundError):
|
| 58 |
+
current_async_library()
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
@pytest.mark.skipif(
|
| 62 |
+
sys.version_info >= (3, 12),
|
| 63 |
+
reason=
|
| 64 |
+
"curio broken on 3.12 (https://github.com/python-trio/sniffio/pull/42)",
|
| 65 |
+
)
|
| 66 |
+
def test_curio():
|
| 67 |
+
import curio
|
| 68 |
+
|
| 69 |
+
with pytest.raises(AsyncLibraryNotFoundError):
|
| 70 |
+
current_async_library()
|
| 71 |
+
|
| 72 |
+
ran = []
|
| 73 |
+
|
| 74 |
+
async def this_is_curio():
|
| 75 |
+
assert current_async_library() == "curio"
|
| 76 |
+
# Call it a second time to exercise the caching logic
|
| 77 |
+
assert current_async_library() == "curio"
|
| 78 |
+
ran.append(True)
|
| 79 |
+
|
| 80 |
+
curio.run(this_is_curio)
|
| 81 |
+
assert ran == [True]
|
| 82 |
+
|
| 83 |
+
with pytest.raises(AsyncLibraryNotFoundError):
|
| 84 |
+
current_async_library()
|
llava_next/lib/python3.10/site-packages/sniffio/_version.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This file is imported from __init__.py and exec'd from setup.py
|
| 2 |
+
|
| 3 |
+
__version__ = "1.3.1"
|
parrot/lib/python3.10/site-packages/docstring_parser/__init__.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Parse docstrings as per Sphinx notation."""
|
| 2 |
+
|
| 3 |
+
from .common import (
|
| 4 |
+
Docstring,
|
| 5 |
+
DocstringDeprecated,
|
| 6 |
+
DocstringMeta,
|
| 7 |
+
DocstringParam,
|
| 8 |
+
DocstringRaises,
|
| 9 |
+
DocstringReturns,
|
| 10 |
+
DocstringStyle,
|
| 11 |
+
ParseError,
|
| 12 |
+
RenderingStyle,
|
| 13 |
+
)
|
| 14 |
+
from .parser import compose, parse, parse_from_object
|
| 15 |
+
from .util import combine_docstrings
|
| 16 |
+
|
| 17 |
+
Style = DocstringStyle # backwards compatibility
|
| 18 |
+
|
| 19 |
+
__all__ = [
|
| 20 |
+
"parse",
|
| 21 |
+
"parse_from_object",
|
| 22 |
+
"combine_docstrings",
|
| 23 |
+
"compose",
|
| 24 |
+
"ParseError",
|
| 25 |
+
"Docstring",
|
| 26 |
+
"DocstringMeta",
|
| 27 |
+
"DocstringParam",
|
| 28 |
+
"DocstringRaises",
|
| 29 |
+
"DocstringReturns",
|
| 30 |
+
"DocstringDeprecated",
|
| 31 |
+
"DocstringStyle",
|
| 32 |
+
"RenderingStyle",
|
| 33 |
+
"Style",
|
| 34 |
+
]
|
parrot/lib/python3.10/site-packages/docstring_parser/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (701 Bytes). View file
|
|
|
parrot/lib/python3.10/site-packages/docstring_parser/__pycache__/common.cpython-310.pyc
ADDED
|
Binary file (7.32 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/docstring_parser/__pycache__/epydoc.cpython-310.pyc
ADDED
|
Binary file (5.46 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/docstring_parser/__pycache__/google.cpython-310.pyc
ADDED
|
Binary file (9.92 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/docstring_parser/__pycache__/numpydoc.cpython-310.pyc
ADDED
|
Binary file (15.3 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/docstring_parser/__pycache__/parser.cpython-310.pyc
ADDED
|
Binary file (3.03 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/docstring_parser/__pycache__/rest.cpython-310.pyc
ADDED
|
Binary file (5.57 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/docstring_parser/attrdoc.py
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Attribute docstrings parsing.
|
| 2 |
+
|
| 3 |
+
.. seealso:: https://peps.python.org/pep-0257/#what-is-a-docstring
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import ast
|
| 7 |
+
import inspect
|
| 8 |
+
import sys
|
| 9 |
+
import textwrap
|
| 10 |
+
import typing as T
|
| 11 |
+
from types import ModuleType
|
| 12 |
+
|
| 13 |
+
from .common import Docstring, DocstringParam
|
| 14 |
+
|
| 15 |
+
ast_constant_attr = {ast.Constant: "value"}
|
| 16 |
+
|
| 17 |
+
if sys.version_info[:2] <= (3, 7):
|
| 18 |
+
ast_constant_attr.update(
|
| 19 |
+
{
|
| 20 |
+
ast.NameConstant: "value",
|
| 21 |
+
ast.Num: "n",
|
| 22 |
+
ast.Str: "s",
|
| 23 |
+
}
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def ast_get_constant_value(node: ast.AST) -> T.Any:
|
| 28 |
+
"""Return the constant's value if the given node is a constant."""
|
| 29 |
+
return getattr(node, ast_constant_attr[node.__class__])
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
def ast_unparse(node: ast.AST) -> T.Optional[str]:
|
| 33 |
+
"""Convert the AST node to source code as a string."""
|
| 34 |
+
if hasattr(ast, "unparse"):
|
| 35 |
+
return ast.unparse(node)
|
| 36 |
+
# Support simple cases in Python < 3.9
|
| 37 |
+
if isinstance(node, (ast.Str, ast.Num, ast.NameConstant, ast.Constant)):
|
| 38 |
+
return str(ast_get_constant_value(node))
|
| 39 |
+
if isinstance(node, ast.Name):
|
| 40 |
+
return node.id
|
| 41 |
+
return None
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def ast_is_literal_str(node: ast.AST) -> bool:
|
| 45 |
+
"""Return True if the given node is a literal string."""
|
| 46 |
+
return (
|
| 47 |
+
isinstance(node, ast.Expr)
|
| 48 |
+
and isinstance(node.value, (ast.Constant, ast.Str))
|
| 49 |
+
and isinstance(ast_get_constant_value(node.value), str)
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def ast_get_attribute(
|
| 54 |
+
node: ast.AST,
|
| 55 |
+
) -> T.Optional[T.Tuple[str, T.Optional[str], T.Optional[str]]]:
|
| 56 |
+
"""Return name, type and default if the given node is an attribute."""
|
| 57 |
+
if isinstance(node, (ast.Assign, ast.AnnAssign)):
|
| 58 |
+
target = (
|
| 59 |
+
node.targets[0] if isinstance(node, ast.Assign) else node.target
|
| 60 |
+
)
|
| 61 |
+
if isinstance(target, ast.Name):
|
| 62 |
+
type_str = None
|
| 63 |
+
if isinstance(node, ast.AnnAssign):
|
| 64 |
+
type_str = ast_unparse(node.annotation)
|
| 65 |
+
default = None
|
| 66 |
+
if node.value:
|
| 67 |
+
default = ast_unparse(node.value)
|
| 68 |
+
return target.id, type_str, default
|
| 69 |
+
return None
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
class AttributeDocstrings(ast.NodeVisitor):
|
| 73 |
+
"""An ast.NodeVisitor that collects attribute docstrings."""
|
| 74 |
+
|
| 75 |
+
attr_docs = None
|
| 76 |
+
prev_attr = None
|
| 77 |
+
|
| 78 |
+
def visit(self, node):
|
| 79 |
+
if self.prev_attr and ast_is_literal_str(node):
|
| 80 |
+
attr_name, attr_type, attr_default = self.prev_attr
|
| 81 |
+
self.attr_docs[attr_name] = (
|
| 82 |
+
ast_get_constant_value(node.value),
|
| 83 |
+
attr_type,
|
| 84 |
+
attr_default,
|
| 85 |
+
)
|
| 86 |
+
self.prev_attr = ast_get_attribute(node)
|
| 87 |
+
if isinstance(node, (ast.ClassDef, ast.Module)):
|
| 88 |
+
self.generic_visit(node)
|
| 89 |
+
|
| 90 |
+
def get_attr_docs(
|
| 91 |
+
self, component: T.Any
|
| 92 |
+
) -> T.Dict[str, T.Tuple[str, T.Optional[str], T.Optional[str]]]:
|
| 93 |
+
"""Get attribute docstrings from the given component.
|
| 94 |
+
|
| 95 |
+
:param component: component to process (class or module)
|
| 96 |
+
:returns: for each attribute docstring, a tuple with (description,
|
| 97 |
+
type, default)
|
| 98 |
+
"""
|
| 99 |
+
self.attr_docs = {}
|
| 100 |
+
self.prev_attr = None
|
| 101 |
+
try:
|
| 102 |
+
source = textwrap.dedent(inspect.getsource(component))
|
| 103 |
+
except OSError:
|
| 104 |
+
pass
|
| 105 |
+
else:
|
| 106 |
+
tree = ast.parse(source)
|
| 107 |
+
if inspect.ismodule(component):
|
| 108 |
+
self.visit(tree)
|
| 109 |
+
elif isinstance(tree, ast.Module) and isinstance(
|
| 110 |
+
tree.body[0], ast.ClassDef
|
| 111 |
+
):
|
| 112 |
+
self.visit(tree.body[0])
|
| 113 |
+
return self.attr_docs
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
def add_attribute_docstrings(
|
| 117 |
+
obj: T.Union[type, ModuleType], docstring: Docstring
|
| 118 |
+
) -> None:
|
| 119 |
+
"""Add attribute docstrings found in the object's source code.
|
| 120 |
+
|
| 121 |
+
:param obj: object from which to parse attribute docstrings
|
| 122 |
+
:param docstring: Docstring object where found attributes are added
|
| 123 |
+
:returns: list with names of added attributes
|
| 124 |
+
"""
|
| 125 |
+
params = set(p.arg_name for p in docstring.params)
|
| 126 |
+
for arg_name, (description, type_name, default) in (
|
| 127 |
+
AttributeDocstrings().get_attr_docs(obj).items()
|
| 128 |
+
):
|
| 129 |
+
if arg_name not in params:
|
| 130 |
+
param = DocstringParam(
|
| 131 |
+
args=["attribute", arg_name],
|
| 132 |
+
description=description,
|
| 133 |
+
arg_name=arg_name,
|
| 134 |
+
type_name=type_name,
|
| 135 |
+
is_optional=default is not None,
|
| 136 |
+
default=default,
|
| 137 |
+
)
|
| 138 |
+
docstring.meta.append(param)
|
parrot/lib/python3.10/site-packages/docstring_parser/common.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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Common methods for parsing."""
|
| 2 |
+
import enum
|
| 3 |
+
import typing as T
|
| 4 |
+
|
| 5 |
+
PARAM_KEYWORDS = {
|
| 6 |
+
"param",
|
| 7 |
+
"parameter",
|
| 8 |
+
"arg",
|
| 9 |
+
"argument",
|
| 10 |
+
"attribute",
|
| 11 |
+
"key",
|
| 12 |
+
"keyword",
|
| 13 |
+
}
|
| 14 |
+
RAISES_KEYWORDS = {"raises", "raise", "except", "exception"}
|
| 15 |
+
DEPRECATION_KEYWORDS = {"deprecation", "deprecated"}
|
| 16 |
+
RETURNS_KEYWORDS = {"return", "returns"}
|
| 17 |
+
YIELDS_KEYWORDS = {"yield", "yields"}
|
| 18 |
+
EXAMPLES_KEYWORDS = {"example", "examples"}
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
class ParseError(RuntimeError):
|
| 22 |
+
"""Base class for all parsing related errors."""
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
class DocstringStyle(enum.Enum):
|
| 26 |
+
"""Docstring style."""
|
| 27 |
+
|
| 28 |
+
REST = 1
|
| 29 |
+
GOOGLE = 2
|
| 30 |
+
NUMPYDOC = 3
|
| 31 |
+
EPYDOC = 4
|
| 32 |
+
AUTO = 255
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
class RenderingStyle(enum.Enum):
|
| 36 |
+
"""Rendering style when unparsing parsed docstrings."""
|
| 37 |
+
|
| 38 |
+
COMPACT = 1
|
| 39 |
+
CLEAN = 2
|
| 40 |
+
EXPANDED = 3
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
class DocstringMeta:
|
| 44 |
+
"""Docstring meta information.
|
| 45 |
+
|
| 46 |
+
Symbolizes lines in form of
|
| 47 |
+
|
| 48 |
+
:param arg: description
|
| 49 |
+
:raises ValueError: if something happens
|
| 50 |
+
"""
|
| 51 |
+
|
| 52 |
+
def __init__(
|
| 53 |
+
self, args: T.List[str], description: T.Optional[str]
|
| 54 |
+
) -> None:
|
| 55 |
+
"""Initialize self.
|
| 56 |
+
|
| 57 |
+
:param args: list of arguments. The exact content of this variable is
|
| 58 |
+
dependent on the kind of docstring; it's used to distinguish
|
| 59 |
+
between custom docstring meta information items.
|
| 60 |
+
:param description: associated docstring description.
|
| 61 |
+
"""
|
| 62 |
+
self.args = args
|
| 63 |
+
self.description = description
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
class DocstringParam(DocstringMeta):
|
| 67 |
+
"""DocstringMeta symbolizing :param metadata."""
|
| 68 |
+
|
| 69 |
+
def __init__(
|
| 70 |
+
self,
|
| 71 |
+
args: T.List[str],
|
| 72 |
+
description: T.Optional[str],
|
| 73 |
+
arg_name: str,
|
| 74 |
+
type_name: T.Optional[str],
|
| 75 |
+
is_optional: T.Optional[bool],
|
| 76 |
+
default: T.Optional[str],
|
| 77 |
+
) -> None:
|
| 78 |
+
"""Initialize self."""
|
| 79 |
+
super().__init__(args, description)
|
| 80 |
+
self.arg_name = arg_name
|
| 81 |
+
self.type_name = type_name
|
| 82 |
+
self.is_optional = is_optional
|
| 83 |
+
self.default = default
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
class DocstringReturns(DocstringMeta):
|
| 87 |
+
"""DocstringMeta symbolizing :returns or :yields metadata."""
|
| 88 |
+
|
| 89 |
+
def __init__(
|
| 90 |
+
self,
|
| 91 |
+
args: T.List[str],
|
| 92 |
+
description: T.Optional[str],
|
| 93 |
+
type_name: T.Optional[str],
|
| 94 |
+
is_generator: bool,
|
| 95 |
+
return_name: T.Optional[str] = None,
|
| 96 |
+
) -> None:
|
| 97 |
+
"""Initialize self."""
|
| 98 |
+
super().__init__(args, description)
|
| 99 |
+
self.type_name = type_name
|
| 100 |
+
self.is_generator = is_generator
|
| 101 |
+
self.return_name = return_name
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
class DocstringRaises(DocstringMeta):
|
| 105 |
+
"""DocstringMeta symbolizing :raises metadata."""
|
| 106 |
+
|
| 107 |
+
def __init__(
|
| 108 |
+
self,
|
| 109 |
+
args: T.List[str],
|
| 110 |
+
description: T.Optional[str],
|
| 111 |
+
type_name: T.Optional[str],
|
| 112 |
+
) -> None:
|
| 113 |
+
"""Initialize self."""
|
| 114 |
+
super().__init__(args, description)
|
| 115 |
+
self.type_name = type_name
|
| 116 |
+
self.description = description
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
class DocstringDeprecated(DocstringMeta):
|
| 120 |
+
"""DocstringMeta symbolizing deprecation metadata."""
|
| 121 |
+
|
| 122 |
+
def __init__(
|
| 123 |
+
self,
|
| 124 |
+
args: T.List[str],
|
| 125 |
+
description: T.Optional[str],
|
| 126 |
+
version: T.Optional[str],
|
| 127 |
+
) -> None:
|
| 128 |
+
"""Initialize self."""
|
| 129 |
+
super().__init__(args, description)
|
| 130 |
+
self.version = version
|
| 131 |
+
self.description = description
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
class DocstringExample(DocstringMeta):
|
| 135 |
+
"""DocstringMeta symbolizing example metadata."""
|
| 136 |
+
|
| 137 |
+
def __init__(
|
| 138 |
+
self,
|
| 139 |
+
args: T.List[str],
|
| 140 |
+
snippet: T.Optional[str],
|
| 141 |
+
description: T.Optional[str],
|
| 142 |
+
) -> None:
|
| 143 |
+
"""Initialize self."""
|
| 144 |
+
super().__init__(args, description)
|
| 145 |
+
self.snippet = snippet
|
| 146 |
+
self.description = description
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
class Docstring:
|
| 150 |
+
"""Docstring object representation."""
|
| 151 |
+
|
| 152 |
+
def __init__(
|
| 153 |
+
self,
|
| 154 |
+
style=None, # type: T.Optional[DocstringStyle]
|
| 155 |
+
) -> None:
|
| 156 |
+
"""Initialize self."""
|
| 157 |
+
self.short_description = None # type: T.Optional[str]
|
| 158 |
+
self.long_description = None # type: T.Optional[str]
|
| 159 |
+
self.blank_after_short_description = False
|
| 160 |
+
self.blank_after_long_description = False
|
| 161 |
+
self.meta = [] # type: T.List[DocstringMeta]
|
| 162 |
+
self.style = style # type: T.Optional[DocstringStyle]
|
| 163 |
+
|
| 164 |
+
@property
|
| 165 |
+
def description(self) -> T.Optional[str]:
|
| 166 |
+
"""Return the full description of the function
|
| 167 |
+
|
| 168 |
+
Returns None if the docstring did not include any description
|
| 169 |
+
"""
|
| 170 |
+
ret = []
|
| 171 |
+
if self.short_description:
|
| 172 |
+
ret.append(self.short_description)
|
| 173 |
+
if self.blank_after_short_description:
|
| 174 |
+
ret.append("")
|
| 175 |
+
if self.long_description:
|
| 176 |
+
ret.append(self.long_description)
|
| 177 |
+
|
| 178 |
+
if not ret:
|
| 179 |
+
return None
|
| 180 |
+
|
| 181 |
+
return "\n".join(ret)
|
| 182 |
+
|
| 183 |
+
@property
|
| 184 |
+
def params(self) -> T.List[DocstringParam]:
|
| 185 |
+
"""Return a list of information on function params."""
|
| 186 |
+
return [item for item in self.meta if isinstance(item, DocstringParam)]
|
| 187 |
+
|
| 188 |
+
@property
|
| 189 |
+
def raises(self) -> T.List[DocstringRaises]:
|
| 190 |
+
"""Return a list of information on the exceptions that the function
|
| 191 |
+
may raise.
|
| 192 |
+
"""
|
| 193 |
+
return [
|
| 194 |
+
item for item in self.meta if isinstance(item, DocstringRaises)
|
| 195 |
+
]
|
| 196 |
+
|
| 197 |
+
@property
|
| 198 |
+
def returns(self) -> T.Optional[DocstringReturns]:
|
| 199 |
+
"""Return a single information on function return.
|
| 200 |
+
|
| 201 |
+
Takes the first return information.
|
| 202 |
+
"""
|
| 203 |
+
for item in self.meta:
|
| 204 |
+
if isinstance(item, DocstringReturns):
|
| 205 |
+
return item
|
| 206 |
+
return None
|
| 207 |
+
|
| 208 |
+
@property
|
| 209 |
+
def many_returns(self) -> T.List[DocstringReturns]:
|
| 210 |
+
"""Return a list of information on function return."""
|
| 211 |
+
return [
|
| 212 |
+
item for item in self.meta if isinstance(item, DocstringReturns)
|
| 213 |
+
]
|
| 214 |
+
|
| 215 |
+
@property
|
| 216 |
+
def deprecation(self) -> T.Optional[DocstringDeprecated]:
|
| 217 |
+
"""Return a single information on function deprecation notes."""
|
| 218 |
+
for item in self.meta:
|
| 219 |
+
if isinstance(item, DocstringDeprecated):
|
| 220 |
+
return item
|
| 221 |
+
return None
|
| 222 |
+
|
| 223 |
+
@property
|
| 224 |
+
def examples(self) -> T.List[DocstringExample]:
|
| 225 |
+
"""Return a list of information on function examples."""
|
| 226 |
+
return [
|
| 227 |
+
item for item in self.meta if isinstance(item, DocstringExample)
|
| 228 |
+
]
|
parrot/lib/python3.10/site-packages/docstring_parser/epydoc.py
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Epyoc-style docstring parsing.
|
| 2 |
+
|
| 3 |
+
.. seealso:: http://epydoc.sourceforge.net/manual-fields.html
|
| 4 |
+
"""
|
| 5 |
+
import inspect
|
| 6 |
+
import re
|
| 7 |
+
import typing as T
|
| 8 |
+
|
| 9 |
+
from .common import (
|
| 10 |
+
Docstring,
|
| 11 |
+
DocstringMeta,
|
| 12 |
+
DocstringParam,
|
| 13 |
+
DocstringRaises,
|
| 14 |
+
DocstringReturns,
|
| 15 |
+
DocstringStyle,
|
| 16 |
+
ParseError,
|
| 17 |
+
RenderingStyle,
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def _clean_str(string: str) -> T.Optional[str]:
|
| 22 |
+
string = string.strip()
|
| 23 |
+
if len(string) > 0:
|
| 24 |
+
return string
|
| 25 |
+
return None
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def parse(text: str) -> Docstring:
|
| 29 |
+
"""Parse the epydoc-style docstring into its components.
|
| 30 |
+
|
| 31 |
+
:returns: parsed docstring
|
| 32 |
+
"""
|
| 33 |
+
ret = Docstring(style=DocstringStyle.EPYDOC)
|
| 34 |
+
if not text:
|
| 35 |
+
return ret
|
| 36 |
+
|
| 37 |
+
text = inspect.cleandoc(text)
|
| 38 |
+
match = re.search("^@", text, flags=re.M)
|
| 39 |
+
if match:
|
| 40 |
+
desc_chunk = text[: match.start()]
|
| 41 |
+
meta_chunk = text[match.start() :]
|
| 42 |
+
else:
|
| 43 |
+
desc_chunk = text
|
| 44 |
+
meta_chunk = ""
|
| 45 |
+
|
| 46 |
+
parts = desc_chunk.split("\n", 1)
|
| 47 |
+
ret.short_description = parts[0] or None
|
| 48 |
+
if len(parts) > 1:
|
| 49 |
+
long_desc_chunk = parts[1] or ""
|
| 50 |
+
ret.blank_after_short_description = long_desc_chunk.startswith("\n")
|
| 51 |
+
ret.blank_after_long_description = long_desc_chunk.endswith("\n\n")
|
| 52 |
+
ret.long_description = long_desc_chunk.strip() or None
|
| 53 |
+
|
| 54 |
+
param_pattern = re.compile(
|
| 55 |
+
r"(param|keyword|type)(\s+[_A-z][_A-z0-9]*\??):"
|
| 56 |
+
)
|
| 57 |
+
raise_pattern = re.compile(r"(raise)(\s+[_A-z][_A-z0-9]*\??)?:")
|
| 58 |
+
return_pattern = re.compile(r"(return|rtype|yield|ytype):")
|
| 59 |
+
meta_pattern = re.compile(
|
| 60 |
+
r"([_A-z][_A-z0-9]+)((\s+[_A-z][_A-z0-9]*\??)*):"
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
# tokenize
|
| 64 |
+
stream: T.List[T.Tuple[str, str, T.List[str], str]] = []
|
| 65 |
+
for match in re.finditer(
|
| 66 |
+
r"(^@.*?)(?=^@|\Z)", meta_chunk, flags=re.S | re.M
|
| 67 |
+
):
|
| 68 |
+
chunk = match.group(0)
|
| 69 |
+
if not chunk:
|
| 70 |
+
continue
|
| 71 |
+
|
| 72 |
+
param_match = re.search(param_pattern, chunk)
|
| 73 |
+
raise_match = re.search(raise_pattern, chunk)
|
| 74 |
+
return_match = re.search(return_pattern, chunk)
|
| 75 |
+
meta_match = re.search(meta_pattern, chunk)
|
| 76 |
+
|
| 77 |
+
match = param_match or raise_match or return_match or meta_match
|
| 78 |
+
if not match:
|
| 79 |
+
raise ParseError(f'Error parsing meta information near "{chunk}".')
|
| 80 |
+
|
| 81 |
+
desc_chunk = chunk[match.end() :]
|
| 82 |
+
if param_match:
|
| 83 |
+
base = "param"
|
| 84 |
+
key: str = match.group(1)
|
| 85 |
+
args = [match.group(2).strip()]
|
| 86 |
+
elif raise_match:
|
| 87 |
+
base = "raise"
|
| 88 |
+
key: str = match.group(1)
|
| 89 |
+
args = [] if match.group(2) is None else [match.group(2).strip()]
|
| 90 |
+
elif return_match:
|
| 91 |
+
base = "return"
|
| 92 |
+
key: str = match.group(1)
|
| 93 |
+
args = []
|
| 94 |
+
else:
|
| 95 |
+
base = "meta"
|
| 96 |
+
key: str = match.group(1)
|
| 97 |
+
token = _clean_str(match.group(2).strip())
|
| 98 |
+
args = [] if token is None else re.split(r"\s+", token)
|
| 99 |
+
|
| 100 |
+
# Make sure we didn't match some existing keyword in an incorrect
|
| 101 |
+
# way here:
|
| 102 |
+
if key in [
|
| 103 |
+
"param",
|
| 104 |
+
"keyword",
|
| 105 |
+
"type",
|
| 106 |
+
"return",
|
| 107 |
+
"rtype",
|
| 108 |
+
"yield",
|
| 109 |
+
"ytype",
|
| 110 |
+
]:
|
| 111 |
+
raise ParseError(
|
| 112 |
+
f'Error parsing meta information near "{chunk}".'
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
desc = desc_chunk.strip()
|
| 116 |
+
if "\n" in desc:
|
| 117 |
+
first_line, rest = desc.split("\n", 1)
|
| 118 |
+
desc = first_line + "\n" + inspect.cleandoc(rest)
|
| 119 |
+
stream.append((base, key, args, desc))
|
| 120 |
+
|
| 121 |
+
# Combine type_name, arg_name, and description information
|
| 122 |
+
params: T.Dict[str, T.Dict[str, T.Any]] = {}
|
| 123 |
+
for (base, key, args, desc) in stream:
|
| 124 |
+
if base not in ["param", "return"]:
|
| 125 |
+
continue # nothing to do
|
| 126 |
+
|
| 127 |
+
(arg_name,) = args or ("return",)
|
| 128 |
+
info = params.setdefault(arg_name, {})
|
| 129 |
+
info_key = "type_name" if "type" in key else "description"
|
| 130 |
+
info[info_key] = desc
|
| 131 |
+
|
| 132 |
+
if base == "return":
|
| 133 |
+
is_generator = key in {"ytype", "yield"}
|
| 134 |
+
if info.setdefault("is_generator", is_generator) != is_generator:
|
| 135 |
+
raise ParseError(
|
| 136 |
+
f'Error parsing meta information for "{arg_name}".'
|
| 137 |
+
)
|
| 138 |
+
|
| 139 |
+
is_done: T.Dict[str, bool] = {}
|
| 140 |
+
for (base, key, args, desc) in stream:
|
| 141 |
+
if base == "param" and not is_done.get(args[0], False):
|
| 142 |
+
(arg_name,) = args
|
| 143 |
+
info = params[arg_name]
|
| 144 |
+
type_name = info.get("type_name")
|
| 145 |
+
|
| 146 |
+
if type_name and type_name.endswith("?"):
|
| 147 |
+
is_optional = True
|
| 148 |
+
type_name = type_name[:-1]
|
| 149 |
+
else:
|
| 150 |
+
is_optional = False
|
| 151 |
+
|
| 152 |
+
match = re.match(r".*defaults to (.+)", desc, flags=re.DOTALL)
|
| 153 |
+
default = match.group(1).rstrip(".") if match else None
|
| 154 |
+
|
| 155 |
+
meta_item = DocstringParam(
|
| 156 |
+
args=[key, arg_name],
|
| 157 |
+
description=info.get("description"),
|
| 158 |
+
arg_name=arg_name,
|
| 159 |
+
type_name=type_name,
|
| 160 |
+
is_optional=is_optional,
|
| 161 |
+
default=default,
|
| 162 |
+
)
|
| 163 |
+
is_done[arg_name] = True
|
| 164 |
+
elif base == "return" and not is_done.get("return", False):
|
| 165 |
+
info = params["return"]
|
| 166 |
+
meta_item = DocstringReturns(
|
| 167 |
+
args=[key],
|
| 168 |
+
description=info.get("description"),
|
| 169 |
+
type_name=info.get("type_name"),
|
| 170 |
+
is_generator=info.get("is_generator", False),
|
| 171 |
+
)
|
| 172 |
+
is_done["return"] = True
|
| 173 |
+
elif base == "raise":
|
| 174 |
+
(type_name,) = args or (None,)
|
| 175 |
+
meta_item = DocstringRaises(
|
| 176 |
+
args=[key] + args,
|
| 177 |
+
description=desc,
|
| 178 |
+
type_name=type_name,
|
| 179 |
+
)
|
| 180 |
+
elif base == "meta":
|
| 181 |
+
meta_item = DocstringMeta(
|
| 182 |
+
args=[key] + args,
|
| 183 |
+
description=desc,
|
| 184 |
+
)
|
| 185 |
+
else:
|
| 186 |
+
(key, *_) = args or ("return",)
|
| 187 |
+
assert is_done.get(key, False)
|
| 188 |
+
continue # don't append
|
| 189 |
+
|
| 190 |
+
ret.meta.append(meta_item)
|
| 191 |
+
|
| 192 |
+
return ret
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
def compose(
|
| 196 |
+
docstring: Docstring,
|
| 197 |
+
rendering_style: RenderingStyle = RenderingStyle.COMPACT,
|
| 198 |
+
indent: str = " ",
|
| 199 |
+
) -> str:
|
| 200 |
+
"""Render a parsed docstring into docstring text.
|
| 201 |
+
|
| 202 |
+
:param docstring: parsed docstring representation
|
| 203 |
+
:param rendering_style: the style to render docstrings
|
| 204 |
+
:param indent: the characters used as indentation in the docstring string
|
| 205 |
+
:returns: docstring text
|
| 206 |
+
"""
|
| 207 |
+
|
| 208 |
+
def process_desc(desc: T.Optional[str], is_type: bool) -> str:
|
| 209 |
+
if not desc:
|
| 210 |
+
return ""
|
| 211 |
+
|
| 212 |
+
if rendering_style == RenderingStyle.EXPANDED or (
|
| 213 |
+
rendering_style == RenderingStyle.CLEAN and not is_type
|
| 214 |
+
):
|
| 215 |
+
(first, *rest) = desc.splitlines()
|
| 216 |
+
return "\n".join(
|
| 217 |
+
["\n" + indent + first] + [indent + line for line in rest]
|
| 218 |
+
)
|
| 219 |
+
|
| 220 |
+
(first, *rest) = desc.splitlines()
|
| 221 |
+
return "\n".join([" " + first] + [indent + line for line in rest])
|
| 222 |
+
|
| 223 |
+
parts: T.List[str] = []
|
| 224 |
+
if docstring.short_description:
|
| 225 |
+
parts.append(docstring.short_description)
|
| 226 |
+
if docstring.blank_after_short_description:
|
| 227 |
+
parts.append("")
|
| 228 |
+
if docstring.long_description:
|
| 229 |
+
parts.append(docstring.long_description)
|
| 230 |
+
if docstring.blank_after_long_description:
|
| 231 |
+
parts.append("")
|
| 232 |
+
|
| 233 |
+
for meta in docstring.meta:
|
| 234 |
+
if isinstance(meta, DocstringParam):
|
| 235 |
+
if meta.type_name:
|
| 236 |
+
type_name = (
|
| 237 |
+
f"{meta.type_name}?"
|
| 238 |
+
if meta.is_optional
|
| 239 |
+
else meta.type_name
|
| 240 |
+
)
|
| 241 |
+
text = f"@type {meta.arg_name}:"
|
| 242 |
+
text += process_desc(type_name, True)
|
| 243 |
+
parts.append(text)
|
| 244 |
+
text = f"@param {meta.arg_name}:" + process_desc(
|
| 245 |
+
meta.description, False
|
| 246 |
+
)
|
| 247 |
+
parts.append(text)
|
| 248 |
+
elif isinstance(meta, DocstringReturns):
|
| 249 |
+
(arg_key, type_key) = (
|
| 250 |
+
("yield", "ytype")
|
| 251 |
+
if meta.is_generator
|
| 252 |
+
else ("return", "rtype")
|
| 253 |
+
)
|
| 254 |
+
if meta.type_name:
|
| 255 |
+
text = f"@{type_key}:" + process_desc(meta.type_name, True)
|
| 256 |
+
parts.append(text)
|
| 257 |
+
if meta.description:
|
| 258 |
+
text = f"@{arg_key}:" + process_desc(meta.description, False)
|
| 259 |
+
parts.append(text)
|
| 260 |
+
elif isinstance(meta, DocstringRaises):
|
| 261 |
+
text = f"@raise {meta.type_name}:" if meta.type_name else "@raise:"
|
| 262 |
+
text += process_desc(meta.description, False)
|
| 263 |
+
parts.append(text)
|
| 264 |
+
else:
|
| 265 |
+
text = f'@{" ".join(meta.args)}:'
|
| 266 |
+
text += process_desc(meta.description, False)
|
| 267 |
+
parts.append(text)
|
| 268 |
+
return "\n".join(parts)
|
parrot/lib/python3.10/site-packages/docstring_parser/google.py
ADDED
|
@@ -0,0 +1,408 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Google-style docstring parsing."""
|
| 2 |
+
|
| 3 |
+
import inspect
|
| 4 |
+
import re
|
| 5 |
+
import typing as T
|
| 6 |
+
from collections import OrderedDict, namedtuple
|
| 7 |
+
from enum import IntEnum
|
| 8 |
+
|
| 9 |
+
from .common import (
|
| 10 |
+
EXAMPLES_KEYWORDS,
|
| 11 |
+
PARAM_KEYWORDS,
|
| 12 |
+
RAISES_KEYWORDS,
|
| 13 |
+
RETURNS_KEYWORDS,
|
| 14 |
+
YIELDS_KEYWORDS,
|
| 15 |
+
Docstring,
|
| 16 |
+
DocstringExample,
|
| 17 |
+
DocstringMeta,
|
| 18 |
+
DocstringParam,
|
| 19 |
+
DocstringRaises,
|
| 20 |
+
DocstringReturns,
|
| 21 |
+
DocstringStyle,
|
| 22 |
+
ParseError,
|
| 23 |
+
RenderingStyle,
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
class SectionType(IntEnum):
|
| 28 |
+
"""Types of sections."""
|
| 29 |
+
|
| 30 |
+
SINGULAR = 0
|
| 31 |
+
"""For sections like examples."""
|
| 32 |
+
|
| 33 |
+
MULTIPLE = 1
|
| 34 |
+
"""For sections like params."""
|
| 35 |
+
|
| 36 |
+
SINGULAR_OR_MULTIPLE = 2
|
| 37 |
+
"""For sections like returns or yields."""
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
class Section(namedtuple("SectionBase", "title key type")):
|
| 41 |
+
"""A docstring section."""
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
GOOGLE_TYPED_ARG_REGEX = re.compile(r"\s*(.+?)\s*\(\s*(.*[^\s]+)\s*\)")
|
| 45 |
+
GOOGLE_ARG_DESC_REGEX = re.compile(r".*\. Defaults to (.+)\.")
|
| 46 |
+
MULTIPLE_PATTERN = re.compile(r"(\s*[^:\s]+:)|([^:]*\]:.*)")
|
| 47 |
+
|
| 48 |
+
DEFAULT_SECTIONS = [
|
| 49 |
+
Section("Arguments", "param", SectionType.MULTIPLE),
|
| 50 |
+
Section("Args", "param", SectionType.MULTIPLE),
|
| 51 |
+
Section("Parameters", "param", SectionType.MULTIPLE),
|
| 52 |
+
Section("Params", "param", SectionType.MULTIPLE),
|
| 53 |
+
Section("Raises", "raises", SectionType.MULTIPLE),
|
| 54 |
+
Section("Exceptions", "raises", SectionType.MULTIPLE),
|
| 55 |
+
Section("Except", "raises", SectionType.MULTIPLE),
|
| 56 |
+
Section("Attributes", "attribute", SectionType.MULTIPLE),
|
| 57 |
+
Section("Example", "examples", SectionType.SINGULAR),
|
| 58 |
+
Section("Examples", "examples", SectionType.SINGULAR),
|
| 59 |
+
Section("Returns", "returns", SectionType.SINGULAR_OR_MULTIPLE),
|
| 60 |
+
Section("Yields", "yields", SectionType.SINGULAR_OR_MULTIPLE),
|
| 61 |
+
]
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
class GoogleParser:
|
| 65 |
+
"""Parser for Google-style docstrings."""
|
| 66 |
+
|
| 67 |
+
def __init__(
|
| 68 |
+
self, sections: T.Optional[T.List[Section]] = None, title_colon=True
|
| 69 |
+
):
|
| 70 |
+
"""Setup sections.
|
| 71 |
+
|
| 72 |
+
:param sections: Recognized sections or None to defaults.
|
| 73 |
+
:param title_colon: require colon after section title.
|
| 74 |
+
"""
|
| 75 |
+
if not sections:
|
| 76 |
+
sections = DEFAULT_SECTIONS
|
| 77 |
+
self.sections = {s.title: s for s in sections}
|
| 78 |
+
self.title_colon = title_colon
|
| 79 |
+
self._setup()
|
| 80 |
+
|
| 81 |
+
def _setup(self):
|
| 82 |
+
if self.title_colon:
|
| 83 |
+
colon = ":"
|
| 84 |
+
else:
|
| 85 |
+
colon = ""
|
| 86 |
+
self.titles_re = re.compile(
|
| 87 |
+
"^("
|
| 88 |
+
+ "|".join(f"({t})" for t in self.sections)
|
| 89 |
+
+ ")"
|
| 90 |
+
+ colon
|
| 91 |
+
+ "[ \t\r\f\v]*$",
|
| 92 |
+
flags=re.M,
|
| 93 |
+
)
|
| 94 |
+
|
| 95 |
+
def _build_meta(self, text: str, title: str) -> DocstringMeta:
|
| 96 |
+
"""Build docstring element.
|
| 97 |
+
|
| 98 |
+
:param text: docstring element text
|
| 99 |
+
:param title: title of section containing element
|
| 100 |
+
:return:
|
| 101 |
+
"""
|
| 102 |
+
|
| 103 |
+
section = self.sections[title]
|
| 104 |
+
|
| 105 |
+
if (
|
| 106 |
+
section.type == SectionType.SINGULAR_OR_MULTIPLE
|
| 107 |
+
and not MULTIPLE_PATTERN.match(text)
|
| 108 |
+
) or section.type == SectionType.SINGULAR:
|
| 109 |
+
return self._build_single_meta(section, text)
|
| 110 |
+
|
| 111 |
+
if ":" not in text:
|
| 112 |
+
raise ParseError(f"Expected a colon in {text!r}.")
|
| 113 |
+
|
| 114 |
+
# Split spec and description
|
| 115 |
+
before, desc = text.split(":", 1)
|
| 116 |
+
if desc:
|
| 117 |
+
desc = desc[1:] if desc[0] == " " else desc
|
| 118 |
+
if "\n" in desc:
|
| 119 |
+
first_line, rest = desc.split("\n", 1)
|
| 120 |
+
desc = first_line + "\n" + inspect.cleandoc(rest)
|
| 121 |
+
desc = desc.strip("\n")
|
| 122 |
+
|
| 123 |
+
return self._build_multi_meta(section, before, desc)
|
| 124 |
+
|
| 125 |
+
@staticmethod
|
| 126 |
+
def _build_single_meta(section: Section, desc: str) -> DocstringMeta:
|
| 127 |
+
if section.key in RETURNS_KEYWORDS | YIELDS_KEYWORDS:
|
| 128 |
+
return DocstringReturns(
|
| 129 |
+
args=[section.key],
|
| 130 |
+
description=desc,
|
| 131 |
+
type_name=None,
|
| 132 |
+
is_generator=section.key in YIELDS_KEYWORDS,
|
| 133 |
+
)
|
| 134 |
+
if section.key in RAISES_KEYWORDS:
|
| 135 |
+
return DocstringRaises(
|
| 136 |
+
args=[section.key], description=desc, type_name=None
|
| 137 |
+
)
|
| 138 |
+
if section.key in EXAMPLES_KEYWORDS:
|
| 139 |
+
return DocstringExample(
|
| 140 |
+
args=[section.key], snippet=None, description=desc
|
| 141 |
+
)
|
| 142 |
+
if section.key in PARAM_KEYWORDS:
|
| 143 |
+
raise ParseError("Expected paramenter name.")
|
| 144 |
+
return DocstringMeta(args=[section.key], description=desc)
|
| 145 |
+
|
| 146 |
+
@staticmethod
|
| 147 |
+
def _build_multi_meta(
|
| 148 |
+
section: Section, before: str, desc: str
|
| 149 |
+
) -> DocstringMeta:
|
| 150 |
+
if section.key in PARAM_KEYWORDS:
|
| 151 |
+
match = GOOGLE_TYPED_ARG_REGEX.match(before)
|
| 152 |
+
if match:
|
| 153 |
+
arg_name, type_name = match.group(1, 2)
|
| 154 |
+
if type_name.endswith(", optional"):
|
| 155 |
+
is_optional = True
|
| 156 |
+
type_name = type_name[:-10]
|
| 157 |
+
elif type_name.endswith("?"):
|
| 158 |
+
is_optional = True
|
| 159 |
+
type_name = type_name[:-1]
|
| 160 |
+
else:
|
| 161 |
+
is_optional = False
|
| 162 |
+
else:
|
| 163 |
+
arg_name, type_name = before, None
|
| 164 |
+
is_optional = None
|
| 165 |
+
|
| 166 |
+
match = GOOGLE_ARG_DESC_REGEX.match(desc)
|
| 167 |
+
default = match.group(1) if match else None
|
| 168 |
+
|
| 169 |
+
return DocstringParam(
|
| 170 |
+
args=[section.key, before],
|
| 171 |
+
description=desc,
|
| 172 |
+
arg_name=arg_name,
|
| 173 |
+
type_name=type_name,
|
| 174 |
+
is_optional=is_optional,
|
| 175 |
+
default=default,
|
| 176 |
+
)
|
| 177 |
+
if section.key in RETURNS_KEYWORDS | YIELDS_KEYWORDS:
|
| 178 |
+
return DocstringReturns(
|
| 179 |
+
args=[section.key, before],
|
| 180 |
+
description=desc,
|
| 181 |
+
type_name=before,
|
| 182 |
+
is_generator=section.key in YIELDS_KEYWORDS,
|
| 183 |
+
)
|
| 184 |
+
if section.key in RAISES_KEYWORDS:
|
| 185 |
+
return DocstringRaises(
|
| 186 |
+
args=[section.key, before], description=desc, type_name=before
|
| 187 |
+
)
|
| 188 |
+
return DocstringMeta(args=[section.key, before], description=desc)
|
| 189 |
+
|
| 190 |
+
def add_section(self, section: Section):
|
| 191 |
+
"""Add or replace a section.
|
| 192 |
+
|
| 193 |
+
:param section: The new section.
|
| 194 |
+
"""
|
| 195 |
+
|
| 196 |
+
self.sections[section.title] = section
|
| 197 |
+
self._setup()
|
| 198 |
+
|
| 199 |
+
def parse(self, text: str) -> Docstring:
|
| 200 |
+
"""Parse the Google-style docstring into its components.
|
| 201 |
+
|
| 202 |
+
:returns: parsed docstring
|
| 203 |
+
"""
|
| 204 |
+
ret = Docstring(style=DocstringStyle.GOOGLE)
|
| 205 |
+
if not text:
|
| 206 |
+
return ret
|
| 207 |
+
|
| 208 |
+
# Clean according to PEP-0257
|
| 209 |
+
text = inspect.cleandoc(text)
|
| 210 |
+
|
| 211 |
+
# Find first title and split on its position
|
| 212 |
+
match = self.titles_re.search(text)
|
| 213 |
+
if match:
|
| 214 |
+
desc_chunk = text[: match.start()]
|
| 215 |
+
meta_chunk = text[match.start() :]
|
| 216 |
+
else:
|
| 217 |
+
desc_chunk = text
|
| 218 |
+
meta_chunk = ""
|
| 219 |
+
|
| 220 |
+
# Break description into short and long parts
|
| 221 |
+
parts = desc_chunk.split("\n", 1)
|
| 222 |
+
ret.short_description = parts[0] or None
|
| 223 |
+
if len(parts) > 1:
|
| 224 |
+
long_desc_chunk = parts[1] or ""
|
| 225 |
+
ret.blank_after_short_description = long_desc_chunk.startswith(
|
| 226 |
+
"\n"
|
| 227 |
+
)
|
| 228 |
+
ret.blank_after_long_description = long_desc_chunk.endswith("\n\n")
|
| 229 |
+
ret.long_description = long_desc_chunk.strip() or None
|
| 230 |
+
|
| 231 |
+
# Split by sections determined by titles
|
| 232 |
+
matches = list(self.titles_re.finditer(meta_chunk))
|
| 233 |
+
if not matches:
|
| 234 |
+
return ret
|
| 235 |
+
splits = []
|
| 236 |
+
for j in range(len(matches) - 1):
|
| 237 |
+
splits.append((matches[j].end(), matches[j + 1].start()))
|
| 238 |
+
splits.append((matches[-1].end(), len(meta_chunk)))
|
| 239 |
+
|
| 240 |
+
chunks = OrderedDict() # type: T.Mapping[str,str]
|
| 241 |
+
for j, (start, end) in enumerate(splits):
|
| 242 |
+
title = matches[j].group(1)
|
| 243 |
+
if title not in self.sections:
|
| 244 |
+
continue
|
| 245 |
+
|
| 246 |
+
# Clear Any Unknown Meta
|
| 247 |
+
# Ref: https://github.com/rr-/docstring_parser/issues/29
|
| 248 |
+
meta_details = meta_chunk[start:end]
|
| 249 |
+
unknown_meta = re.search(r"\n\S", meta_details)
|
| 250 |
+
if unknown_meta is not None:
|
| 251 |
+
meta_details = meta_details[: unknown_meta.start()]
|
| 252 |
+
|
| 253 |
+
chunks[title] = meta_details.strip("\n")
|
| 254 |
+
if not chunks:
|
| 255 |
+
return ret
|
| 256 |
+
|
| 257 |
+
# Add elements from each chunk
|
| 258 |
+
for title, chunk in chunks.items():
|
| 259 |
+
# Determine indent
|
| 260 |
+
indent_match = re.search(r"^\s*", chunk)
|
| 261 |
+
if not indent_match:
|
| 262 |
+
raise ParseError(f'Can\'t infer indent from "{chunk}"')
|
| 263 |
+
indent = indent_match.group()
|
| 264 |
+
|
| 265 |
+
# Check for singular elements
|
| 266 |
+
if self.sections[title].type in [
|
| 267 |
+
SectionType.SINGULAR,
|
| 268 |
+
SectionType.SINGULAR_OR_MULTIPLE,
|
| 269 |
+
]:
|
| 270 |
+
part = inspect.cleandoc(chunk)
|
| 271 |
+
ret.meta.append(self._build_meta(part, title))
|
| 272 |
+
continue
|
| 273 |
+
|
| 274 |
+
# Split based on lines which have exactly that indent
|
| 275 |
+
_re = "^" + indent + r"(?=\S)"
|
| 276 |
+
c_matches = list(re.finditer(_re, chunk, flags=re.M))
|
| 277 |
+
if not c_matches:
|
| 278 |
+
raise ParseError(f'No specification for "{title}": "{chunk}"')
|
| 279 |
+
c_splits = []
|
| 280 |
+
for j in range(len(c_matches) - 1):
|
| 281 |
+
c_splits.append((c_matches[j].end(), c_matches[j + 1].start()))
|
| 282 |
+
c_splits.append((c_matches[-1].end(), len(chunk)))
|
| 283 |
+
for j, (start, end) in enumerate(c_splits):
|
| 284 |
+
part = chunk[start:end].strip("\n")
|
| 285 |
+
ret.meta.append(self._build_meta(part, title))
|
| 286 |
+
|
| 287 |
+
return ret
|
| 288 |
+
|
| 289 |
+
|
| 290 |
+
def parse(text: str) -> Docstring:
|
| 291 |
+
"""Parse the Google-style docstring into its components.
|
| 292 |
+
|
| 293 |
+
:returns: parsed docstring
|
| 294 |
+
"""
|
| 295 |
+
return GoogleParser().parse(text)
|
| 296 |
+
|
| 297 |
+
|
| 298 |
+
def compose(
|
| 299 |
+
docstring: Docstring,
|
| 300 |
+
rendering_style: RenderingStyle = RenderingStyle.COMPACT,
|
| 301 |
+
indent: str = " ",
|
| 302 |
+
) -> str:
|
| 303 |
+
"""Render a parsed docstring into docstring text.
|
| 304 |
+
|
| 305 |
+
:param docstring: parsed docstring representation
|
| 306 |
+
:param rendering_style: the style to render docstrings
|
| 307 |
+
:param indent: the characters used as indentation in the docstring string
|
| 308 |
+
:returns: docstring text
|
| 309 |
+
"""
|
| 310 |
+
|
| 311 |
+
def process_one(
|
| 312 |
+
one: T.Union[DocstringParam, DocstringReturns, DocstringRaises]
|
| 313 |
+
):
|
| 314 |
+
head = ""
|
| 315 |
+
|
| 316 |
+
if isinstance(one, DocstringParam):
|
| 317 |
+
head += one.arg_name or ""
|
| 318 |
+
elif isinstance(one, DocstringReturns):
|
| 319 |
+
head += one.return_name or ""
|
| 320 |
+
|
| 321 |
+
if isinstance(one, DocstringParam) and one.is_optional:
|
| 322 |
+
optional = (
|
| 323 |
+
"?"
|
| 324 |
+
if rendering_style == RenderingStyle.COMPACT
|
| 325 |
+
else ", optional"
|
| 326 |
+
)
|
| 327 |
+
else:
|
| 328 |
+
optional = ""
|
| 329 |
+
|
| 330 |
+
if one.type_name and head:
|
| 331 |
+
head += f" ({one.type_name}{optional}):"
|
| 332 |
+
elif one.type_name:
|
| 333 |
+
head += f"{one.type_name}{optional}:"
|
| 334 |
+
else:
|
| 335 |
+
head += ":"
|
| 336 |
+
head = indent + head
|
| 337 |
+
|
| 338 |
+
if one.description and rendering_style == RenderingStyle.EXPANDED:
|
| 339 |
+
body = f"\n{indent}{indent}".join(
|
| 340 |
+
[head] + one.description.splitlines()
|
| 341 |
+
)
|
| 342 |
+
parts.append(body)
|
| 343 |
+
elif one.description:
|
| 344 |
+
(first, *rest) = one.description.splitlines()
|
| 345 |
+
body = f"\n{indent}{indent}".join([head + " " + first] + rest)
|
| 346 |
+
parts.append(body)
|
| 347 |
+
else:
|
| 348 |
+
parts.append(head)
|
| 349 |
+
|
| 350 |
+
def process_sect(name: str, args: T.List[T.Any]):
|
| 351 |
+
if args:
|
| 352 |
+
parts.append(name)
|
| 353 |
+
for arg in args:
|
| 354 |
+
process_one(arg)
|
| 355 |
+
parts.append("")
|
| 356 |
+
|
| 357 |
+
parts: T.List[str] = []
|
| 358 |
+
if docstring.short_description:
|
| 359 |
+
parts.append(docstring.short_description)
|
| 360 |
+
if docstring.blank_after_short_description:
|
| 361 |
+
parts.append("")
|
| 362 |
+
|
| 363 |
+
if docstring.long_description:
|
| 364 |
+
parts.append(docstring.long_description)
|
| 365 |
+
if docstring.blank_after_long_description:
|
| 366 |
+
parts.append("")
|
| 367 |
+
|
| 368 |
+
process_sect(
|
| 369 |
+
"Args:", [p for p in docstring.params or [] if p.args[0] == "param"]
|
| 370 |
+
)
|
| 371 |
+
|
| 372 |
+
process_sect(
|
| 373 |
+
"Attributes:",
|
| 374 |
+
[p for p in docstring.params or [] if p.args[0] == "attribute"],
|
| 375 |
+
)
|
| 376 |
+
|
| 377 |
+
process_sect(
|
| 378 |
+
"Returns:",
|
| 379 |
+
[p for p in docstring.many_returns or [] if not p.is_generator],
|
| 380 |
+
)
|
| 381 |
+
|
| 382 |
+
process_sect(
|
| 383 |
+
"Yields:", [p for p in docstring.many_returns or [] if p.is_generator]
|
| 384 |
+
)
|
| 385 |
+
|
| 386 |
+
process_sect("Raises:", docstring.raises or [])
|
| 387 |
+
|
| 388 |
+
if docstring.returns and not docstring.many_returns:
|
| 389 |
+
ret = docstring.returns
|
| 390 |
+
parts.append("Yields:" if ret else "Returns:")
|
| 391 |
+
parts.append("-" * len(parts[-1]))
|
| 392 |
+
process_one(ret)
|
| 393 |
+
|
| 394 |
+
for meta in docstring.meta:
|
| 395 |
+
if isinstance(
|
| 396 |
+
meta, (DocstringParam, DocstringReturns, DocstringRaises)
|
| 397 |
+
):
|
| 398 |
+
continue # Already handled
|
| 399 |
+
parts.append(meta.args[0].replace("_", "").title() + ":")
|
| 400 |
+
if meta.description:
|
| 401 |
+
lines = [indent + l for l in meta.description.splitlines()]
|
| 402 |
+
parts.append("\n".join(lines))
|
| 403 |
+
parts.append("")
|
| 404 |
+
|
| 405 |
+
while parts and not parts[-1]:
|
| 406 |
+
parts.pop()
|
| 407 |
+
|
| 408 |
+
return "\n".join(parts)
|
parrot/lib/python3.10/site-packages/docstring_parser/numpydoc.py
ADDED
|
@@ -0,0 +1,532 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Numpydoc-style docstring parsing.
|
| 2 |
+
|
| 3 |
+
:see: https://numpydoc.readthedocs.io/en/latest/format.html
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
import inspect
|
| 7 |
+
import itertools
|
| 8 |
+
import re
|
| 9 |
+
import typing as T
|
| 10 |
+
from textwrap import dedent
|
| 11 |
+
|
| 12 |
+
from .common import (
|
| 13 |
+
Docstring,
|
| 14 |
+
DocstringDeprecated,
|
| 15 |
+
DocstringExample,
|
| 16 |
+
DocstringMeta,
|
| 17 |
+
DocstringParam,
|
| 18 |
+
DocstringRaises,
|
| 19 |
+
DocstringReturns,
|
| 20 |
+
DocstringStyle,
|
| 21 |
+
RenderingStyle,
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def _pairwise(iterable: T.Iterable, end=None) -> T.Iterable:
|
| 26 |
+
left, right = itertools.tee(iterable)
|
| 27 |
+
next(right, None)
|
| 28 |
+
return itertools.zip_longest(left, right, fillvalue=end)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def _clean_str(string: str) -> T.Optional[str]:
|
| 32 |
+
string = string.strip()
|
| 33 |
+
if len(string) > 0:
|
| 34 |
+
return string
|
| 35 |
+
return None
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
KV_REGEX = re.compile(r"^[^\s].*$", flags=re.M)
|
| 39 |
+
PARAM_KEY_REGEX = re.compile(r"^(?P<name>.*?)(?:\s*:\s*(?P<type>.*?))?$")
|
| 40 |
+
PARAM_OPTIONAL_REGEX = re.compile(r"(?P<type>.*?)(?:, optional|\(optional\))$")
|
| 41 |
+
|
| 42 |
+
# numpydoc format has no formal grammar for this,
|
| 43 |
+
# but we can make some educated guesses...
|
| 44 |
+
PARAM_DEFAULT_REGEX = re.compile(
|
| 45 |
+
r"(?<!\S)[Dd]efault(?: is | = |: |s to |)\s*(?P<value>[\w\-\.]*\w)"
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
RETURN_KEY_REGEX = re.compile(r"^(?:(?P<name>.*?)\s*:\s*)?(?P<type>.*?)$")
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
class Section:
|
| 52 |
+
"""Numpydoc section parser.
|
| 53 |
+
|
| 54 |
+
:param title: section title. For most sections, this is a heading like
|
| 55 |
+
"Parameters" which appears on its own line, underlined by
|
| 56 |
+
en-dashes ('-') on the following line.
|
| 57 |
+
:param key: meta key string. In the parsed ``DocstringMeta`` instance this
|
| 58 |
+
will be the first element of the ``args`` attribute list.
|
| 59 |
+
"""
|
| 60 |
+
|
| 61 |
+
def __init__(self, title: str, key: str) -> None:
|
| 62 |
+
self.title = title
|
| 63 |
+
self.key = key
|
| 64 |
+
|
| 65 |
+
@property
|
| 66 |
+
def title_pattern(self) -> str:
|
| 67 |
+
"""Regular expression pattern matching this section's header.
|
| 68 |
+
|
| 69 |
+
This pattern will match this instance's ``title`` attribute in
|
| 70 |
+
an anonymous group.
|
| 71 |
+
"""
|
| 72 |
+
dashes = "-" * len(self.title)
|
| 73 |
+
return rf"^({self.title})\s*?\n{dashes}\s*$"
|
| 74 |
+
|
| 75 |
+
def parse(self, text: str) -> T.Iterable[DocstringMeta]:
|
| 76 |
+
"""Parse ``DocstringMeta`` objects from the body of this section.
|
| 77 |
+
|
| 78 |
+
:param text: section body text. Should be cleaned with
|
| 79 |
+
``inspect.cleandoc`` before parsing.
|
| 80 |
+
"""
|
| 81 |
+
yield DocstringMeta([self.key], description=_clean_str(text))
|
| 82 |
+
|
| 83 |
+
|
| 84 |
+
class _KVSection(Section):
|
| 85 |
+
"""Base parser for numpydoc sections with key-value syntax.
|
| 86 |
+
|
| 87 |
+
E.g. sections that look like this:
|
| 88 |
+
key
|
| 89 |
+
value
|
| 90 |
+
key2 : type
|
| 91 |
+
values can also span...
|
| 92 |
+
... multiple lines
|
| 93 |
+
"""
|
| 94 |
+
|
| 95 |
+
def _parse_item(self, key: str, value: str) -> DocstringMeta:
|
| 96 |
+
pass
|
| 97 |
+
|
| 98 |
+
def parse(self, text: str) -> T.Iterable[DocstringMeta]:
|
| 99 |
+
for match, next_match in _pairwise(KV_REGEX.finditer(text)):
|
| 100 |
+
start = match.end()
|
| 101 |
+
end = next_match.start() if next_match is not None else None
|
| 102 |
+
value = text[start:end]
|
| 103 |
+
yield self._parse_item(
|
| 104 |
+
key=match.group(), value=inspect.cleandoc(value)
|
| 105 |
+
)
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
class _SphinxSection(Section):
|
| 109 |
+
"""Base parser for numpydoc sections with sphinx-style syntax.
|
| 110 |
+
|
| 111 |
+
E.g. sections that look like this:
|
| 112 |
+
.. title:: something
|
| 113 |
+
possibly over multiple lines
|
| 114 |
+
"""
|
| 115 |
+
|
| 116 |
+
@property
|
| 117 |
+
def title_pattern(self) -> str:
|
| 118 |
+
return rf"^\.\.\s*({self.title})\s*::"
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
class ParamSection(_KVSection):
|
| 122 |
+
"""Parser for numpydoc parameter sections.
|
| 123 |
+
|
| 124 |
+
E.g. any section that looks like this:
|
| 125 |
+
arg_name
|
| 126 |
+
arg_description
|
| 127 |
+
arg_2 : type, optional
|
| 128 |
+
descriptions can also span...
|
| 129 |
+
... multiple lines
|
| 130 |
+
"""
|
| 131 |
+
|
| 132 |
+
def _parse_item(self, key: str, value: str) -> DocstringParam:
|
| 133 |
+
match = PARAM_KEY_REGEX.match(key)
|
| 134 |
+
arg_name = type_name = is_optional = None
|
| 135 |
+
if match is not None:
|
| 136 |
+
arg_name = match.group("name")
|
| 137 |
+
type_name = match.group("type")
|
| 138 |
+
if type_name is not None:
|
| 139 |
+
optional_match = PARAM_OPTIONAL_REGEX.match(type_name)
|
| 140 |
+
if optional_match is not None:
|
| 141 |
+
type_name = optional_match.group("type")
|
| 142 |
+
is_optional = True
|
| 143 |
+
else:
|
| 144 |
+
is_optional = False
|
| 145 |
+
|
| 146 |
+
default = None
|
| 147 |
+
if len(value) > 0:
|
| 148 |
+
default_match = PARAM_DEFAULT_REGEX.search(value)
|
| 149 |
+
if default_match is not None:
|
| 150 |
+
default = default_match.group("value")
|
| 151 |
+
|
| 152 |
+
return DocstringParam(
|
| 153 |
+
args=[self.key, arg_name],
|
| 154 |
+
description=_clean_str(value),
|
| 155 |
+
arg_name=arg_name,
|
| 156 |
+
type_name=type_name,
|
| 157 |
+
is_optional=is_optional,
|
| 158 |
+
default=default,
|
| 159 |
+
)
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
class RaisesSection(_KVSection):
|
| 163 |
+
"""Parser for numpydoc raises sections.
|
| 164 |
+
|
| 165 |
+
E.g. any section that looks like this:
|
| 166 |
+
ValueError
|
| 167 |
+
A description of what might raise ValueError
|
| 168 |
+
"""
|
| 169 |
+
|
| 170 |
+
def _parse_item(self, key: str, value: str) -> DocstringRaises:
|
| 171 |
+
return DocstringRaises(
|
| 172 |
+
args=[self.key, key],
|
| 173 |
+
description=_clean_str(value),
|
| 174 |
+
type_name=key if len(key) > 0 else None,
|
| 175 |
+
)
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
class ReturnsSection(_KVSection):
|
| 179 |
+
"""Parser for numpydoc returns sections.
|
| 180 |
+
|
| 181 |
+
E.g. any section that looks like this:
|
| 182 |
+
return_name : type
|
| 183 |
+
A description of this returned value
|
| 184 |
+
another_type
|
| 185 |
+
Return names are optional, types are required
|
| 186 |
+
"""
|
| 187 |
+
|
| 188 |
+
is_generator = False
|
| 189 |
+
|
| 190 |
+
def _parse_item(self, key: str, value: str) -> DocstringReturns:
|
| 191 |
+
match = RETURN_KEY_REGEX.match(key)
|
| 192 |
+
if match is not None:
|
| 193 |
+
return_name = match.group("name")
|
| 194 |
+
type_name = match.group("type")
|
| 195 |
+
else:
|
| 196 |
+
return_name = None
|
| 197 |
+
type_name = None
|
| 198 |
+
|
| 199 |
+
return DocstringReturns(
|
| 200 |
+
args=[self.key],
|
| 201 |
+
description=_clean_str(value),
|
| 202 |
+
type_name=type_name,
|
| 203 |
+
is_generator=self.is_generator,
|
| 204 |
+
return_name=return_name,
|
| 205 |
+
)
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
class YieldsSection(ReturnsSection):
|
| 209 |
+
"""Parser for numpydoc generator "yields" sections."""
|
| 210 |
+
|
| 211 |
+
is_generator = True
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
class DeprecationSection(_SphinxSection):
|
| 215 |
+
"""Parser for numpydoc "deprecation warning" sections."""
|
| 216 |
+
|
| 217 |
+
def parse(self, text: str) -> T.Iterable[DocstringDeprecated]:
|
| 218 |
+
version, desc, *_ = text.split(sep="\n", maxsplit=1) + [None, None]
|
| 219 |
+
|
| 220 |
+
if desc is not None:
|
| 221 |
+
desc = _clean_str(inspect.cleandoc(desc))
|
| 222 |
+
|
| 223 |
+
yield DocstringDeprecated(
|
| 224 |
+
args=[self.key], description=desc, version=_clean_str(version)
|
| 225 |
+
)
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
class ExamplesSection(Section):
|
| 229 |
+
"""Parser for numpydoc examples sections.
|
| 230 |
+
|
| 231 |
+
E.g. any section that looks like this:
|
| 232 |
+
>>> import numpy.matlib
|
| 233 |
+
>>> np.matlib.empty((2, 2)) # filled with random data
|
| 234 |
+
matrix([[ 6.76425276e-320, 9.79033856e-307], # random
|
| 235 |
+
[ 7.39337286e-309, 3.22135945e-309]])
|
| 236 |
+
>>> np.matlib.empty((2, 2), dtype=int)
|
| 237 |
+
matrix([[ 6600475, 0], # random
|
| 238 |
+
[ 6586976, 22740995]])
|
| 239 |
+
"""
|
| 240 |
+
|
| 241 |
+
def parse(self, text: str) -> T.Iterable[DocstringMeta]:
|
| 242 |
+
"""Parse ``DocstringExample`` objects from the body of this section.
|
| 243 |
+
|
| 244 |
+
:param text: section body text. Should be cleaned with
|
| 245 |
+
``inspect.cleandoc`` before parsing.
|
| 246 |
+
"""
|
| 247 |
+
lines = dedent(text).strip().splitlines()
|
| 248 |
+
while lines:
|
| 249 |
+
snippet_lines = []
|
| 250 |
+
description_lines = []
|
| 251 |
+
while lines:
|
| 252 |
+
if not lines[0].startswith(">>>"):
|
| 253 |
+
break
|
| 254 |
+
snippet_lines.append(lines.pop(0))
|
| 255 |
+
while lines:
|
| 256 |
+
if lines[0].startswith(">>>"):
|
| 257 |
+
break
|
| 258 |
+
description_lines.append(lines.pop(0))
|
| 259 |
+
yield DocstringExample(
|
| 260 |
+
[self.key],
|
| 261 |
+
snippet="\n".join(snippet_lines) if snippet_lines else None,
|
| 262 |
+
description="\n".join(description_lines),
|
| 263 |
+
)
|
| 264 |
+
|
| 265 |
+
|
| 266 |
+
DEFAULT_SECTIONS = [
|
| 267 |
+
ParamSection("Parameters", "param"),
|
| 268 |
+
ParamSection("Params", "param"),
|
| 269 |
+
ParamSection("Arguments", "param"),
|
| 270 |
+
ParamSection("Args", "param"),
|
| 271 |
+
ParamSection("Other Parameters", "other_param"),
|
| 272 |
+
ParamSection("Other Params", "other_param"),
|
| 273 |
+
ParamSection("Other Arguments", "other_param"),
|
| 274 |
+
ParamSection("Other Args", "other_param"),
|
| 275 |
+
ParamSection("Receives", "receives"),
|
| 276 |
+
ParamSection("Receive", "receives"),
|
| 277 |
+
RaisesSection("Raises", "raises"),
|
| 278 |
+
RaisesSection("Raise", "raises"),
|
| 279 |
+
RaisesSection("Warns", "warns"),
|
| 280 |
+
RaisesSection("Warn", "warns"),
|
| 281 |
+
ParamSection("Attributes", "attribute"),
|
| 282 |
+
ParamSection("Attribute", "attribute"),
|
| 283 |
+
ReturnsSection("Returns", "returns"),
|
| 284 |
+
ReturnsSection("Return", "returns"),
|
| 285 |
+
YieldsSection("Yields", "yields"),
|
| 286 |
+
YieldsSection("Yield", "yields"),
|
| 287 |
+
ExamplesSection("Examples", "examples"),
|
| 288 |
+
ExamplesSection("Example", "examples"),
|
| 289 |
+
Section("Warnings", "warnings"),
|
| 290 |
+
Section("Warning", "warnings"),
|
| 291 |
+
Section("See Also", "see_also"),
|
| 292 |
+
Section("Related", "see_also"),
|
| 293 |
+
Section("Notes", "notes"),
|
| 294 |
+
Section("Note", "notes"),
|
| 295 |
+
Section("References", "references"),
|
| 296 |
+
Section("Reference", "references"),
|
| 297 |
+
DeprecationSection("deprecated", "deprecation"),
|
| 298 |
+
]
|
| 299 |
+
|
| 300 |
+
|
| 301 |
+
class NumpydocParser:
|
| 302 |
+
"""Parser for numpydoc-style docstrings."""
|
| 303 |
+
|
| 304 |
+
def __init__(self, sections: T.Optional[T.Dict[str, Section]] = None):
|
| 305 |
+
"""Setup sections.
|
| 306 |
+
|
| 307 |
+
:param sections: Recognized sections or None to defaults.
|
| 308 |
+
"""
|
| 309 |
+
sections = sections or DEFAULT_SECTIONS
|
| 310 |
+
self.sections = {s.title: s for s in sections}
|
| 311 |
+
self._setup()
|
| 312 |
+
|
| 313 |
+
def _setup(self):
|
| 314 |
+
self.titles_re = re.compile(
|
| 315 |
+
r"|".join(s.title_pattern for s in self.sections.values()),
|
| 316 |
+
flags=re.M,
|
| 317 |
+
)
|
| 318 |
+
|
| 319 |
+
def add_section(self, section: Section):
|
| 320 |
+
"""Add or replace a section.
|
| 321 |
+
|
| 322 |
+
:param section: The new section.
|
| 323 |
+
"""
|
| 324 |
+
|
| 325 |
+
self.sections[section.title] = section
|
| 326 |
+
self._setup()
|
| 327 |
+
|
| 328 |
+
def parse(self, text: str) -> Docstring:
|
| 329 |
+
"""Parse the numpy-style docstring into its components.
|
| 330 |
+
|
| 331 |
+
:returns: parsed docstring
|
| 332 |
+
"""
|
| 333 |
+
ret = Docstring(style=DocstringStyle.NUMPYDOC)
|
| 334 |
+
if not text:
|
| 335 |
+
return ret
|
| 336 |
+
|
| 337 |
+
# Clean according to PEP-0257
|
| 338 |
+
text = inspect.cleandoc(text)
|
| 339 |
+
|
| 340 |
+
# Find first title and split on its position
|
| 341 |
+
match = self.titles_re.search(text)
|
| 342 |
+
if match:
|
| 343 |
+
desc_chunk = text[: match.start()]
|
| 344 |
+
meta_chunk = text[match.start() :]
|
| 345 |
+
else:
|
| 346 |
+
desc_chunk = text
|
| 347 |
+
meta_chunk = ""
|
| 348 |
+
|
| 349 |
+
# Break description into short and long parts
|
| 350 |
+
parts = desc_chunk.split("\n", 1)
|
| 351 |
+
ret.short_description = parts[0] or None
|
| 352 |
+
if len(parts) > 1:
|
| 353 |
+
long_desc_chunk = parts[1] or ""
|
| 354 |
+
ret.blank_after_short_description = long_desc_chunk.startswith(
|
| 355 |
+
"\n"
|
| 356 |
+
)
|
| 357 |
+
ret.blank_after_long_description = long_desc_chunk.endswith("\n\n")
|
| 358 |
+
ret.long_description = long_desc_chunk.strip() or None
|
| 359 |
+
|
| 360 |
+
for match, nextmatch in _pairwise(self.titles_re.finditer(meta_chunk)):
|
| 361 |
+
title = next(g for g in match.groups() if g is not None)
|
| 362 |
+
factory = self.sections[title]
|
| 363 |
+
|
| 364 |
+
# section chunk starts after the header,
|
| 365 |
+
# ends at the start of the next header
|
| 366 |
+
start = match.end()
|
| 367 |
+
end = nextmatch.start() if nextmatch is not None else None
|
| 368 |
+
ret.meta.extend(factory.parse(meta_chunk[start:end]))
|
| 369 |
+
|
| 370 |
+
return ret
|
| 371 |
+
|
| 372 |
+
|
| 373 |
+
def parse(text: str) -> Docstring:
|
| 374 |
+
"""Parse the numpy-style docstring into its components.
|
| 375 |
+
|
| 376 |
+
:returns: parsed docstring
|
| 377 |
+
"""
|
| 378 |
+
return NumpydocParser().parse(text)
|
| 379 |
+
|
| 380 |
+
|
| 381 |
+
def compose(
|
| 382 |
+
# pylint: disable=W0613
|
| 383 |
+
docstring: Docstring,
|
| 384 |
+
rendering_style: RenderingStyle = RenderingStyle.COMPACT,
|
| 385 |
+
indent: str = " ",
|
| 386 |
+
) -> str:
|
| 387 |
+
"""Render a parsed docstring into docstring text.
|
| 388 |
+
|
| 389 |
+
:param docstring: parsed docstring representation
|
| 390 |
+
:param rendering_style: the style to render docstrings
|
| 391 |
+
:param indent: the characters used as indentation in the docstring string
|
| 392 |
+
:returns: docstring text
|
| 393 |
+
"""
|
| 394 |
+
|
| 395 |
+
def process_one(
|
| 396 |
+
one: T.Union[DocstringParam, DocstringReturns, DocstringRaises]
|
| 397 |
+
):
|
| 398 |
+
if isinstance(one, DocstringParam):
|
| 399 |
+
head = one.arg_name
|
| 400 |
+
elif isinstance(one, DocstringReturns):
|
| 401 |
+
head = one.return_name
|
| 402 |
+
else:
|
| 403 |
+
head = None
|
| 404 |
+
|
| 405 |
+
if one.type_name and head:
|
| 406 |
+
head += f" : {one.type_name}"
|
| 407 |
+
elif one.type_name:
|
| 408 |
+
head = one.type_name
|
| 409 |
+
elif not head:
|
| 410 |
+
head = ""
|
| 411 |
+
|
| 412 |
+
if isinstance(one, DocstringParam) and one.is_optional:
|
| 413 |
+
head += ", optional"
|
| 414 |
+
|
| 415 |
+
if one.description:
|
| 416 |
+
body = f"\n{indent}".join([head] + one.description.splitlines())
|
| 417 |
+
parts.append(body)
|
| 418 |
+
else:
|
| 419 |
+
parts.append(head)
|
| 420 |
+
|
| 421 |
+
def process_sect(name: str, args: T.List[T.Any]):
|
| 422 |
+
if args:
|
| 423 |
+
parts.append("")
|
| 424 |
+
parts.append(name)
|
| 425 |
+
parts.append("-" * len(parts[-1]))
|
| 426 |
+
for arg in args:
|
| 427 |
+
process_one(arg)
|
| 428 |
+
|
| 429 |
+
parts: T.List[str] = []
|
| 430 |
+
if docstring.short_description:
|
| 431 |
+
parts.append(docstring.short_description)
|
| 432 |
+
if docstring.blank_after_short_description:
|
| 433 |
+
parts.append("")
|
| 434 |
+
|
| 435 |
+
if docstring.deprecation:
|
| 436 |
+
first = ".. deprecated::"
|
| 437 |
+
if docstring.deprecation.version:
|
| 438 |
+
first += f" {docstring.deprecation.version}"
|
| 439 |
+
if docstring.deprecation.description:
|
| 440 |
+
rest = docstring.deprecation.description.splitlines()
|
| 441 |
+
else:
|
| 442 |
+
rest = []
|
| 443 |
+
sep = f"\n{indent}"
|
| 444 |
+
parts.append(sep.join([first] + rest))
|
| 445 |
+
|
| 446 |
+
if docstring.long_description:
|
| 447 |
+
parts.append(docstring.long_description)
|
| 448 |
+
if docstring.blank_after_long_description:
|
| 449 |
+
parts.append("")
|
| 450 |
+
|
| 451 |
+
process_sect(
|
| 452 |
+
"Parameters",
|
| 453 |
+
[item for item in docstring.params or [] if item.args[0] == "param"],
|
| 454 |
+
)
|
| 455 |
+
|
| 456 |
+
process_sect(
|
| 457 |
+
"Attributes",
|
| 458 |
+
[
|
| 459 |
+
item
|
| 460 |
+
for item in docstring.params or []
|
| 461 |
+
if item.args[0] == "attribute"
|
| 462 |
+
],
|
| 463 |
+
)
|
| 464 |
+
|
| 465 |
+
process_sect(
|
| 466 |
+
"Returns",
|
| 467 |
+
[
|
| 468 |
+
item
|
| 469 |
+
for item in docstring.many_returns or []
|
| 470 |
+
if not item.is_generator
|
| 471 |
+
],
|
| 472 |
+
)
|
| 473 |
+
|
| 474 |
+
process_sect(
|
| 475 |
+
"Yields",
|
| 476 |
+
[item for item in docstring.many_returns or [] if item.is_generator],
|
| 477 |
+
)
|
| 478 |
+
|
| 479 |
+
if docstring.returns and not docstring.many_returns:
|
| 480 |
+
ret = docstring.returns
|
| 481 |
+
parts.append("Yields" if ret else "Returns")
|
| 482 |
+
parts.append("-" * len(parts[-1]))
|
| 483 |
+
process_one(ret)
|
| 484 |
+
|
| 485 |
+
process_sect(
|
| 486 |
+
"Receives",
|
| 487 |
+
[
|
| 488 |
+
item
|
| 489 |
+
for item in docstring.params or []
|
| 490 |
+
if item.args[0] == "receives"
|
| 491 |
+
],
|
| 492 |
+
)
|
| 493 |
+
|
| 494 |
+
process_sect(
|
| 495 |
+
"Other Parameters",
|
| 496 |
+
[
|
| 497 |
+
item
|
| 498 |
+
for item in docstring.params or []
|
| 499 |
+
if item.args[0] == "other_param"
|
| 500 |
+
],
|
| 501 |
+
)
|
| 502 |
+
|
| 503 |
+
process_sect(
|
| 504 |
+
"Raises",
|
| 505 |
+
[item for item in docstring.raises or [] if item.args[0] == "raises"],
|
| 506 |
+
)
|
| 507 |
+
|
| 508 |
+
process_sect(
|
| 509 |
+
"Warns",
|
| 510 |
+
[item for item in docstring.raises or [] if item.args[0] == "warns"],
|
| 511 |
+
)
|
| 512 |
+
|
| 513 |
+
for meta in docstring.meta:
|
| 514 |
+
if isinstance(
|
| 515 |
+
meta,
|
| 516 |
+
(
|
| 517 |
+
DocstringDeprecated,
|
| 518 |
+
DocstringParam,
|
| 519 |
+
DocstringReturns,
|
| 520 |
+
DocstringRaises,
|
| 521 |
+
),
|
| 522 |
+
):
|
| 523 |
+
continue # Already handled
|
| 524 |
+
|
| 525 |
+
parts.append("")
|
| 526 |
+
parts.append(meta.args[0].replace("_", "").title())
|
| 527 |
+
parts.append("-" * len(meta.args[0]))
|
| 528 |
+
|
| 529 |
+
if meta.description:
|
| 530 |
+
parts.append(meta.description)
|
| 531 |
+
|
| 532 |
+
return "\n".join(parts)
|
parrot/lib/python3.10/site-packages/docstring_parser/parser.py
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""The main parsing routine."""
|
| 2 |
+
|
| 3 |
+
import inspect
|
| 4 |
+
import typing as T
|
| 5 |
+
|
| 6 |
+
from docstring_parser import epydoc, google, numpydoc, rest
|
| 7 |
+
from docstring_parser.attrdoc import add_attribute_docstrings
|
| 8 |
+
from docstring_parser.common import (
|
| 9 |
+
Docstring,
|
| 10 |
+
DocstringStyle,
|
| 11 |
+
ParseError,
|
| 12 |
+
RenderingStyle,
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
_STYLE_MAP = {
|
| 16 |
+
DocstringStyle.REST: rest,
|
| 17 |
+
DocstringStyle.GOOGLE: google,
|
| 18 |
+
DocstringStyle.NUMPYDOC: numpydoc,
|
| 19 |
+
DocstringStyle.EPYDOC: epydoc,
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def parse(text: str, style: DocstringStyle = DocstringStyle.AUTO) -> Docstring:
|
| 24 |
+
"""Parse the docstring into its components.
|
| 25 |
+
|
| 26 |
+
:param text: docstring text to parse
|
| 27 |
+
:param style: docstring style
|
| 28 |
+
:returns: parsed docstring representation
|
| 29 |
+
"""
|
| 30 |
+
if style != DocstringStyle.AUTO:
|
| 31 |
+
return _STYLE_MAP[style].parse(text)
|
| 32 |
+
|
| 33 |
+
exc: T.Optional[Exception] = None
|
| 34 |
+
rets = []
|
| 35 |
+
for module in _STYLE_MAP.values():
|
| 36 |
+
try:
|
| 37 |
+
ret = module.parse(text)
|
| 38 |
+
except ParseError as ex:
|
| 39 |
+
exc = ex
|
| 40 |
+
else:
|
| 41 |
+
rets.append(ret)
|
| 42 |
+
|
| 43 |
+
if not rets:
|
| 44 |
+
raise exc
|
| 45 |
+
|
| 46 |
+
return sorted(rets, key=lambda d: len(d.meta), reverse=True)[0]
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def parse_from_object(
|
| 50 |
+
obj: T.Any,
|
| 51 |
+
style: DocstringStyle = DocstringStyle.AUTO,
|
| 52 |
+
) -> Docstring:
|
| 53 |
+
"""Parse the object's docstring(s) into its components.
|
| 54 |
+
|
| 55 |
+
The object can be anything that has a ``__doc__`` attribute. In contrast to
|
| 56 |
+
the ``parse`` function, ``parse_from_object`` is able to parse attribute
|
| 57 |
+
docstrings which are defined in the source code instead of ``__doc__``.
|
| 58 |
+
|
| 59 |
+
Currently only attribute docstrings defined at class and module levels are
|
| 60 |
+
supported. Attribute docstrings defined in ``__init__`` methods are not
|
| 61 |
+
supported.
|
| 62 |
+
|
| 63 |
+
When given a class, only the attribute docstrings of that class are parsed,
|
| 64 |
+
not its inherited classes. This is a design decision. Separate calls to
|
| 65 |
+
this function should be performed to get attribute docstrings of parent
|
| 66 |
+
classes.
|
| 67 |
+
|
| 68 |
+
:param obj: object from which to parse the docstring(s)
|
| 69 |
+
:param style: docstring style
|
| 70 |
+
:returns: parsed docstring representation
|
| 71 |
+
"""
|
| 72 |
+
docstring = parse(obj.__doc__, style=style)
|
| 73 |
+
|
| 74 |
+
if inspect.isclass(obj) or inspect.ismodule(obj):
|
| 75 |
+
add_attribute_docstrings(obj, docstring)
|
| 76 |
+
|
| 77 |
+
return docstring
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def compose(
|
| 81 |
+
docstring: Docstring,
|
| 82 |
+
style: DocstringStyle = DocstringStyle.AUTO,
|
| 83 |
+
rendering_style: RenderingStyle = RenderingStyle.COMPACT,
|
| 84 |
+
indent: str = " ",
|
| 85 |
+
) -> str:
|
| 86 |
+
"""Render a parsed docstring into docstring text.
|
| 87 |
+
|
| 88 |
+
:param docstring: parsed docstring representation
|
| 89 |
+
:param style: docstring style to render
|
| 90 |
+
:param indent: the characters used as indentation in the docstring string
|
| 91 |
+
:returns: docstring text
|
| 92 |
+
"""
|
| 93 |
+
module = _STYLE_MAP[
|
| 94 |
+
docstring.style if style == DocstringStyle.AUTO else style
|
| 95 |
+
]
|
| 96 |
+
return module.compose(
|
| 97 |
+
docstring, rendering_style=rendering_style, indent=indent
|
| 98 |
+
)
|
parrot/lib/python3.10/site-packages/docstring_parser/py.typed
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
# Marker file for PEP 561.
|
parrot/lib/python3.10/site-packages/docstring_parser/rest.py
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""ReST-style docstring parsing."""
|
| 2 |
+
|
| 3 |
+
import inspect
|
| 4 |
+
import re
|
| 5 |
+
import typing as T
|
| 6 |
+
|
| 7 |
+
from .common import (
|
| 8 |
+
DEPRECATION_KEYWORDS,
|
| 9 |
+
PARAM_KEYWORDS,
|
| 10 |
+
RAISES_KEYWORDS,
|
| 11 |
+
RETURNS_KEYWORDS,
|
| 12 |
+
YIELDS_KEYWORDS,
|
| 13 |
+
Docstring,
|
| 14 |
+
DocstringDeprecated,
|
| 15 |
+
DocstringMeta,
|
| 16 |
+
DocstringParam,
|
| 17 |
+
DocstringRaises,
|
| 18 |
+
DocstringReturns,
|
| 19 |
+
DocstringStyle,
|
| 20 |
+
ParseError,
|
| 21 |
+
RenderingStyle,
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def _build_meta(args: T.List[str], desc: str) -> DocstringMeta:
|
| 26 |
+
key = args[0]
|
| 27 |
+
|
| 28 |
+
if key in PARAM_KEYWORDS:
|
| 29 |
+
if len(args) == 3:
|
| 30 |
+
key, type_name, arg_name = args
|
| 31 |
+
if type_name.endswith("?"):
|
| 32 |
+
is_optional = True
|
| 33 |
+
type_name = type_name[:-1]
|
| 34 |
+
else:
|
| 35 |
+
is_optional = False
|
| 36 |
+
elif len(args) == 2:
|
| 37 |
+
key, arg_name = args
|
| 38 |
+
type_name = None
|
| 39 |
+
is_optional = None
|
| 40 |
+
else:
|
| 41 |
+
raise ParseError(
|
| 42 |
+
f"Expected one or two arguments for a {key} keyword."
|
| 43 |
+
)
|
| 44 |
+
|
| 45 |
+
match = re.match(r".*defaults to (.+)", desc, flags=re.DOTALL)
|
| 46 |
+
default = match.group(1).rstrip(".") if match else None
|
| 47 |
+
|
| 48 |
+
return DocstringParam(
|
| 49 |
+
args=args,
|
| 50 |
+
description=desc,
|
| 51 |
+
arg_name=arg_name,
|
| 52 |
+
type_name=type_name,
|
| 53 |
+
is_optional=is_optional,
|
| 54 |
+
default=default,
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
if key in RETURNS_KEYWORDS | YIELDS_KEYWORDS:
|
| 58 |
+
if len(args) == 2:
|
| 59 |
+
type_name = args[1]
|
| 60 |
+
elif len(args) == 1:
|
| 61 |
+
type_name = None
|
| 62 |
+
else:
|
| 63 |
+
raise ParseError(
|
| 64 |
+
f"Expected one or no arguments for a {key} keyword."
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
return DocstringReturns(
|
| 68 |
+
args=args,
|
| 69 |
+
description=desc,
|
| 70 |
+
type_name=type_name,
|
| 71 |
+
is_generator=key in YIELDS_KEYWORDS,
|
| 72 |
+
)
|
| 73 |
+
|
| 74 |
+
if key in DEPRECATION_KEYWORDS:
|
| 75 |
+
match = re.search(
|
| 76 |
+
r"^(?P<version>v?((?:\d+)(?:\.[0-9a-z\.]+))) (?P<desc>.+)",
|
| 77 |
+
desc,
|
| 78 |
+
flags=re.I,
|
| 79 |
+
)
|
| 80 |
+
return DocstringDeprecated(
|
| 81 |
+
args=args,
|
| 82 |
+
version=match.group("version") if match else None,
|
| 83 |
+
description=match.group("desc") if match else desc,
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
if key in RAISES_KEYWORDS:
|
| 87 |
+
if len(args) == 2:
|
| 88 |
+
type_name = args[1]
|
| 89 |
+
elif len(args) == 1:
|
| 90 |
+
type_name = None
|
| 91 |
+
else:
|
| 92 |
+
raise ParseError(
|
| 93 |
+
f"Expected one or no arguments for a {key} keyword."
|
| 94 |
+
)
|
| 95 |
+
return DocstringRaises(
|
| 96 |
+
args=args, description=desc, type_name=type_name
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
return DocstringMeta(args=args, description=desc)
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def parse(text: str) -> Docstring:
|
| 103 |
+
"""Parse the ReST-style docstring into its components.
|
| 104 |
+
|
| 105 |
+
:returns: parsed docstring
|
| 106 |
+
"""
|
| 107 |
+
ret = Docstring(style=DocstringStyle.REST)
|
| 108 |
+
if not text:
|
| 109 |
+
return ret
|
| 110 |
+
|
| 111 |
+
text = inspect.cleandoc(text)
|
| 112 |
+
match = re.search("^:", text, flags=re.M)
|
| 113 |
+
if match:
|
| 114 |
+
desc_chunk = text[: match.start()]
|
| 115 |
+
meta_chunk = text[match.start() :]
|
| 116 |
+
else:
|
| 117 |
+
desc_chunk = text
|
| 118 |
+
meta_chunk = ""
|
| 119 |
+
|
| 120 |
+
parts = desc_chunk.split("\n", 1)
|
| 121 |
+
ret.short_description = parts[0] or None
|
| 122 |
+
if len(parts) > 1:
|
| 123 |
+
long_desc_chunk = parts[1] or ""
|
| 124 |
+
ret.blank_after_short_description = long_desc_chunk.startswith("\n")
|
| 125 |
+
ret.blank_after_long_description = long_desc_chunk.endswith("\n\n")
|
| 126 |
+
ret.long_description = long_desc_chunk.strip() or None
|
| 127 |
+
|
| 128 |
+
types = {}
|
| 129 |
+
rtypes = {}
|
| 130 |
+
for match in re.finditer(
|
| 131 |
+
r"(^:.*?)(?=^:|\Z)", meta_chunk, flags=re.S | re.M
|
| 132 |
+
):
|
| 133 |
+
chunk = match.group(0)
|
| 134 |
+
if not chunk:
|
| 135 |
+
continue
|
| 136 |
+
try:
|
| 137 |
+
args_chunk, desc_chunk = chunk.lstrip(":").split(":", 1)
|
| 138 |
+
except ValueError as ex:
|
| 139 |
+
raise ParseError(
|
| 140 |
+
f'Error parsing meta information near "{chunk}".'
|
| 141 |
+
) from ex
|
| 142 |
+
args = args_chunk.split()
|
| 143 |
+
desc = desc_chunk.strip()
|
| 144 |
+
|
| 145 |
+
if "\n" in desc:
|
| 146 |
+
first_line, rest = desc.split("\n", 1)
|
| 147 |
+
desc = first_line + "\n" + inspect.cleandoc(rest)
|
| 148 |
+
|
| 149 |
+
# Add special handling for :type a: typename
|
| 150 |
+
if len(args) == 2 and args[0] == "type":
|
| 151 |
+
types[args[1]] = desc
|
| 152 |
+
elif len(args) in [1, 2] and args[0] == "rtype":
|
| 153 |
+
rtypes[None if len(args) == 1 else args[1]] = desc
|
| 154 |
+
else:
|
| 155 |
+
ret.meta.append(_build_meta(args, desc))
|
| 156 |
+
|
| 157 |
+
for meta in ret.meta:
|
| 158 |
+
if isinstance(meta, DocstringParam):
|
| 159 |
+
meta.type_name = meta.type_name or types.get(meta.arg_name)
|
| 160 |
+
elif isinstance(meta, DocstringReturns):
|
| 161 |
+
meta.type_name = meta.type_name or rtypes.get(meta.return_name)
|
| 162 |
+
|
| 163 |
+
if not any(isinstance(m, DocstringReturns) for m in ret.meta) and rtypes:
|
| 164 |
+
for (return_name, type_name) in rtypes.items():
|
| 165 |
+
ret.meta.append(
|
| 166 |
+
DocstringReturns(
|
| 167 |
+
args=[],
|
| 168 |
+
type_name=type_name,
|
| 169 |
+
description=None,
|
| 170 |
+
is_generator=False,
|
| 171 |
+
return_name=return_name,
|
| 172 |
+
)
|
| 173 |
+
)
|
| 174 |
+
|
| 175 |
+
return ret
|
| 176 |
+
|
| 177 |
+
|
| 178 |
+
def compose(
|
| 179 |
+
docstring: Docstring,
|
| 180 |
+
rendering_style: RenderingStyle = RenderingStyle.COMPACT,
|
| 181 |
+
indent: str = " ",
|
| 182 |
+
) -> str:
|
| 183 |
+
"""Render a parsed docstring into docstring text.
|
| 184 |
+
|
| 185 |
+
:param docstring: parsed docstring representation
|
| 186 |
+
:param rendering_style: the style to render docstrings
|
| 187 |
+
:param indent: the characters used as indentation in the docstring string
|
| 188 |
+
:returns: docstring text
|
| 189 |
+
"""
|
| 190 |
+
|
| 191 |
+
def process_desc(desc: T.Optional[str]) -> str:
|
| 192 |
+
if not desc:
|
| 193 |
+
return ""
|
| 194 |
+
|
| 195 |
+
if rendering_style == RenderingStyle.CLEAN:
|
| 196 |
+
(first, *rest) = desc.splitlines()
|
| 197 |
+
return "\n".join([" " + first] + [indent + line for line in rest])
|
| 198 |
+
|
| 199 |
+
if rendering_style == RenderingStyle.EXPANDED:
|
| 200 |
+
(first, *rest) = desc.splitlines()
|
| 201 |
+
return "\n".join(
|
| 202 |
+
["\n" + indent + first] + [indent + line for line in rest]
|
| 203 |
+
)
|
| 204 |
+
|
| 205 |
+
return " " + desc
|
| 206 |
+
|
| 207 |
+
parts: T.List[str] = []
|
| 208 |
+
if docstring.short_description:
|
| 209 |
+
parts.append(docstring.short_description)
|
| 210 |
+
if docstring.blank_after_short_description:
|
| 211 |
+
parts.append("")
|
| 212 |
+
if docstring.long_description:
|
| 213 |
+
parts.append(docstring.long_description)
|
| 214 |
+
if docstring.blank_after_long_description:
|
| 215 |
+
parts.append("")
|
| 216 |
+
|
| 217 |
+
for meta in docstring.meta:
|
| 218 |
+
if isinstance(meta, DocstringParam):
|
| 219 |
+
if meta.type_name:
|
| 220 |
+
type_text = (
|
| 221 |
+
f" {meta.type_name}? "
|
| 222 |
+
if meta.is_optional
|
| 223 |
+
else f" {meta.type_name} "
|
| 224 |
+
)
|
| 225 |
+
else:
|
| 226 |
+
type_text = " "
|
| 227 |
+
if rendering_style == RenderingStyle.EXPANDED:
|
| 228 |
+
text = f":param {meta.arg_name}:"
|
| 229 |
+
text += process_desc(meta.description)
|
| 230 |
+
parts.append(text)
|
| 231 |
+
if type_text[:-1]:
|
| 232 |
+
parts.append(f":type {meta.arg_name}:{type_text[:-1]}")
|
| 233 |
+
else:
|
| 234 |
+
text = f":param{type_text}{meta.arg_name}:"
|
| 235 |
+
text += process_desc(meta.description)
|
| 236 |
+
parts.append(text)
|
| 237 |
+
elif isinstance(meta, DocstringReturns):
|
| 238 |
+
type_text = f" {meta.type_name}" if meta.type_name else ""
|
| 239 |
+
key = "yields" if meta.is_generator else "returns"
|
| 240 |
+
|
| 241 |
+
if rendering_style == RenderingStyle.EXPANDED:
|
| 242 |
+
if meta.description:
|
| 243 |
+
text = f":{key}:"
|
| 244 |
+
text += process_desc(meta.description)
|
| 245 |
+
parts.append(text)
|
| 246 |
+
if type_text:
|
| 247 |
+
parts.append(f":rtype:{type_text}")
|
| 248 |
+
else:
|
| 249 |
+
text = f":{key}{type_text}:"
|
| 250 |
+
text += process_desc(meta.description)
|
| 251 |
+
parts.append(text)
|
| 252 |
+
elif isinstance(meta, DocstringRaises):
|
| 253 |
+
type_text = f" {meta.type_name} " if meta.type_name else ""
|
| 254 |
+
text = f":raises{type_text}:" + process_desc(meta.description)
|
| 255 |
+
parts.append(text)
|
| 256 |
+
else:
|
| 257 |
+
text = f':{" ".join(meta.args)}:' + process_desc(meta.description)
|
| 258 |
+
parts.append(text)
|
| 259 |
+
return "\n".join(parts)
|
parrot/lib/python3.10/site-packages/docstring_parser/tests/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
"""Tests for docstring parser."""
|
parrot/lib/python3.10/site-packages/docstring_parser/tests/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (213 Bytes). View file
|
|
|
parrot/lib/python3.10/site-packages/docstring_parser/tests/__pycache__/_pydoctor.cpython-310.pyc
ADDED
|
Binary file (1.13 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/docstring_parser/tests/__pycache__/test_epydoc.cpython-310.pyc
ADDED
|
Binary file (11.7 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/docstring_parser/tests/__pycache__/test_google.cpython-310.pyc
ADDED
|
Binary file (17.6 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/docstring_parser/tests/__pycache__/test_numpydoc.cpython-310.pyc
ADDED
|
Binary file (19.2 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/docstring_parser/tests/__pycache__/test_parse_from_object.cpython-310.pyc
ADDED
|
Binary file (3.91 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/docstring_parser/tests/__pycache__/test_parser.cpython-310.pyc
ADDED
|
Binary file (4.46 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/docstring_parser/tests/__pycache__/test_rest.cpython-310.pyc
ADDED
|
Binary file (10.4 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/docstring_parser/tests/__pycache__/test_util.cpython-310.pyc
ADDED
|
Binary file (1.93 kB). View file
|
|
|
parrot/lib/python3.10/site-packages/docstring_parser/tests/_pydoctor.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Private pydoctor customization code in order to exclude the package
|
| 2 |
+
docstring_parser.tests from the API documentation. Based on Twisted code.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
# pylint: disable=invalid-name
|
| 6 |
+
|
| 7 |
+
try:
|
| 8 |
+
from pydoctor.model import Documentable, PrivacyClass, System
|
| 9 |
+
except ImportError:
|
| 10 |
+
pass
|
| 11 |
+
else:
|
| 12 |
+
|
| 13 |
+
class HidesTestsPydoctorSystem(System):
|
| 14 |
+
"""A PyDoctor "system" used to generate the docs."""
|
| 15 |
+
|
| 16 |
+
def privacyClass(self, documentable: Documentable) -> PrivacyClass:
|
| 17 |
+
"""Report the privacy level for an object. Hide the module
|
| 18 |
+
'docstring_parser.tests'.
|
| 19 |
+
"""
|
| 20 |
+
if documentable.fullName().startswith("docstring_parser.tests"):
|
| 21 |
+
return PrivacyClass.HIDDEN
|
| 22 |
+
return super().privacyClass(documentable)
|
parrot/lib/python3.10/site-packages/docstring_parser/tests/test_epydoc.py
ADDED
|
@@ -0,0 +1,723 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for epydoc-style docstring routines."""
|
| 2 |
+
import typing as T
|
| 3 |
+
|
| 4 |
+
import pytest
|
| 5 |
+
from docstring_parser.common import ParseError, RenderingStyle
|
| 6 |
+
from docstring_parser.epydoc import compose, parse
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
@pytest.mark.parametrize(
|
| 10 |
+
"source, expected",
|
| 11 |
+
[
|
| 12 |
+
("", None),
|
| 13 |
+
("\n", None),
|
| 14 |
+
("Short description", "Short description"),
|
| 15 |
+
("\nShort description\n", "Short description"),
|
| 16 |
+
("\n Short description\n", "Short description"),
|
| 17 |
+
],
|
| 18 |
+
)
|
| 19 |
+
def test_short_description(source: str, expected: str) -> None:
|
| 20 |
+
"""Test parsing short description."""
|
| 21 |
+
docstring = parse(source)
|
| 22 |
+
assert docstring.short_description == expected
|
| 23 |
+
assert docstring.long_description is None
|
| 24 |
+
assert not docstring.meta
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
@pytest.mark.parametrize(
|
| 28 |
+
"source, expected_short_desc, expected_long_desc, expected_blank",
|
| 29 |
+
[
|
| 30 |
+
(
|
| 31 |
+
"Short description\n\nLong description",
|
| 32 |
+
"Short description",
|
| 33 |
+
"Long description",
|
| 34 |
+
True,
|
| 35 |
+
),
|
| 36 |
+
(
|
| 37 |
+
"""
|
| 38 |
+
Short description
|
| 39 |
+
|
| 40 |
+
Long description
|
| 41 |
+
""",
|
| 42 |
+
"Short description",
|
| 43 |
+
"Long description",
|
| 44 |
+
True,
|
| 45 |
+
),
|
| 46 |
+
(
|
| 47 |
+
"""
|
| 48 |
+
Short description
|
| 49 |
+
|
| 50 |
+
Long description
|
| 51 |
+
Second line
|
| 52 |
+
""",
|
| 53 |
+
"Short description",
|
| 54 |
+
"Long description\nSecond line",
|
| 55 |
+
True,
|
| 56 |
+
),
|
| 57 |
+
(
|
| 58 |
+
"Short description\nLong description",
|
| 59 |
+
"Short description",
|
| 60 |
+
"Long description",
|
| 61 |
+
False,
|
| 62 |
+
),
|
| 63 |
+
(
|
| 64 |
+
"""
|
| 65 |
+
Short description
|
| 66 |
+
Long description
|
| 67 |
+
""",
|
| 68 |
+
"Short description",
|
| 69 |
+
"Long description",
|
| 70 |
+
False,
|
| 71 |
+
),
|
| 72 |
+
(
|
| 73 |
+
"\nShort description\nLong description\n",
|
| 74 |
+
"Short description",
|
| 75 |
+
"Long description",
|
| 76 |
+
False,
|
| 77 |
+
),
|
| 78 |
+
(
|
| 79 |
+
"""
|
| 80 |
+
Short description
|
| 81 |
+
Long description
|
| 82 |
+
Second line
|
| 83 |
+
""",
|
| 84 |
+
"Short description",
|
| 85 |
+
"Long description\nSecond line",
|
| 86 |
+
False,
|
| 87 |
+
),
|
| 88 |
+
],
|
| 89 |
+
)
|
| 90 |
+
def test_long_description(
|
| 91 |
+
source: str,
|
| 92 |
+
expected_short_desc: str,
|
| 93 |
+
expected_long_desc: str,
|
| 94 |
+
expected_blank: bool,
|
| 95 |
+
) -> None:
|
| 96 |
+
"""Test parsing long description."""
|
| 97 |
+
docstring = parse(source)
|
| 98 |
+
assert docstring.short_description == expected_short_desc
|
| 99 |
+
assert docstring.long_description == expected_long_desc
|
| 100 |
+
assert docstring.blank_after_short_description == expected_blank
|
| 101 |
+
assert not docstring.meta
|
| 102 |
+
|
| 103 |
+
|
| 104 |
+
@pytest.mark.parametrize(
|
| 105 |
+
"source, expected_short_desc, expected_long_desc, "
|
| 106 |
+
"expected_blank_short_desc, expected_blank_long_desc",
|
| 107 |
+
[
|
| 108 |
+
(
|
| 109 |
+
"""
|
| 110 |
+
Short description
|
| 111 |
+
@meta: asd
|
| 112 |
+
""",
|
| 113 |
+
"Short description",
|
| 114 |
+
None,
|
| 115 |
+
False,
|
| 116 |
+
False,
|
| 117 |
+
),
|
| 118 |
+
(
|
| 119 |
+
"""
|
| 120 |
+
Short description
|
| 121 |
+
Long description
|
| 122 |
+
@meta: asd
|
| 123 |
+
""",
|
| 124 |
+
"Short description",
|
| 125 |
+
"Long description",
|
| 126 |
+
False,
|
| 127 |
+
False,
|
| 128 |
+
),
|
| 129 |
+
(
|
| 130 |
+
"""
|
| 131 |
+
Short description
|
| 132 |
+
First line
|
| 133 |
+
Second line
|
| 134 |
+
@meta: asd
|
| 135 |
+
""",
|
| 136 |
+
"Short description",
|
| 137 |
+
"First line\n Second line",
|
| 138 |
+
False,
|
| 139 |
+
False,
|
| 140 |
+
),
|
| 141 |
+
(
|
| 142 |
+
"""
|
| 143 |
+
Short description
|
| 144 |
+
|
| 145 |
+
First line
|
| 146 |
+
Second line
|
| 147 |
+
@meta: asd
|
| 148 |
+
""",
|
| 149 |
+
"Short description",
|
| 150 |
+
"First line\n Second line",
|
| 151 |
+
True,
|
| 152 |
+
False,
|
| 153 |
+
),
|
| 154 |
+
(
|
| 155 |
+
"""
|
| 156 |
+
Short description
|
| 157 |
+
|
| 158 |
+
First line
|
| 159 |
+
Second line
|
| 160 |
+
|
| 161 |
+
@meta: asd
|
| 162 |
+
""",
|
| 163 |
+
"Short description",
|
| 164 |
+
"First line\n Second line",
|
| 165 |
+
True,
|
| 166 |
+
True,
|
| 167 |
+
),
|
| 168 |
+
(
|
| 169 |
+
"""
|
| 170 |
+
@meta: asd
|
| 171 |
+
""",
|
| 172 |
+
None,
|
| 173 |
+
None,
|
| 174 |
+
False,
|
| 175 |
+
False,
|
| 176 |
+
),
|
| 177 |
+
],
|
| 178 |
+
)
|
| 179 |
+
def test_meta_newlines(
|
| 180 |
+
source: str,
|
| 181 |
+
expected_short_desc: T.Optional[str],
|
| 182 |
+
expected_long_desc: T.Optional[str],
|
| 183 |
+
expected_blank_short_desc: bool,
|
| 184 |
+
expected_blank_long_desc: bool,
|
| 185 |
+
) -> None:
|
| 186 |
+
"""Test parsing newlines around description sections."""
|
| 187 |
+
docstring = parse(source)
|
| 188 |
+
assert docstring.short_description == expected_short_desc
|
| 189 |
+
assert docstring.long_description == expected_long_desc
|
| 190 |
+
assert docstring.blank_after_short_description == expected_blank_short_desc
|
| 191 |
+
assert docstring.blank_after_long_description == expected_blank_long_desc
|
| 192 |
+
assert len(docstring.meta) == 1
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
def test_meta_with_multiline_description() -> None:
|
| 196 |
+
"""Test parsing multiline meta documentation."""
|
| 197 |
+
docstring = parse(
|
| 198 |
+
"""
|
| 199 |
+
Short description
|
| 200 |
+
|
| 201 |
+
@meta: asd
|
| 202 |
+
1
|
| 203 |
+
2
|
| 204 |
+
3
|
| 205 |
+
"""
|
| 206 |
+
)
|
| 207 |
+
assert docstring.short_description == "Short description"
|
| 208 |
+
assert len(docstring.meta) == 1
|
| 209 |
+
assert docstring.meta[0].args == ["meta"]
|
| 210 |
+
assert docstring.meta[0].description == "asd\n1\n 2\n3"
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
def test_multiple_meta() -> None:
|
| 214 |
+
"""Test parsing multiple meta."""
|
| 215 |
+
docstring = parse(
|
| 216 |
+
"""
|
| 217 |
+
Short description
|
| 218 |
+
|
| 219 |
+
@meta1: asd
|
| 220 |
+
1
|
| 221 |
+
2
|
| 222 |
+
3
|
| 223 |
+
@meta2: herp
|
| 224 |
+
@meta3: derp
|
| 225 |
+
"""
|
| 226 |
+
)
|
| 227 |
+
assert docstring.short_description == "Short description"
|
| 228 |
+
assert len(docstring.meta) == 3
|
| 229 |
+
assert docstring.meta[0].args == ["meta1"]
|
| 230 |
+
assert docstring.meta[0].description == "asd\n1\n 2\n3"
|
| 231 |
+
assert docstring.meta[1].args == ["meta2"]
|
| 232 |
+
assert docstring.meta[1].description == "herp"
|
| 233 |
+
assert docstring.meta[2].args == ["meta3"]
|
| 234 |
+
assert docstring.meta[2].description == "derp"
|
| 235 |
+
|
| 236 |
+
|
| 237 |
+
def test_meta_with_args() -> None:
|
| 238 |
+
"""Test parsing meta with additional arguments."""
|
| 239 |
+
docstring = parse(
|
| 240 |
+
"""
|
| 241 |
+
Short description
|
| 242 |
+
|
| 243 |
+
@meta ene due rabe: asd
|
| 244 |
+
"""
|
| 245 |
+
)
|
| 246 |
+
assert docstring.short_description == "Short description"
|
| 247 |
+
assert len(docstring.meta) == 1
|
| 248 |
+
assert docstring.meta[0].args == ["meta", "ene", "due", "rabe"]
|
| 249 |
+
assert docstring.meta[0].description == "asd"
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
def test_params() -> None:
|
| 253 |
+
"""Test parsing params."""
|
| 254 |
+
docstring = parse("Short description")
|
| 255 |
+
assert len(docstring.params) == 0
|
| 256 |
+
|
| 257 |
+
docstring = parse(
|
| 258 |
+
"""
|
| 259 |
+
Short description
|
| 260 |
+
|
| 261 |
+
@param name: description 1
|
| 262 |
+
@param priority: description 2
|
| 263 |
+
@type priority: int
|
| 264 |
+
@param sender: description 3
|
| 265 |
+
@type sender: str?
|
| 266 |
+
@param message: description 4, defaults to 'hello'
|
| 267 |
+
@type message: str?
|
| 268 |
+
@param multiline: long description 5,
|
| 269 |
+
defaults to 'bye'
|
| 270 |
+
@type multiline: str?
|
| 271 |
+
"""
|
| 272 |
+
)
|
| 273 |
+
assert len(docstring.params) == 5
|
| 274 |
+
assert docstring.params[0].arg_name == "name"
|
| 275 |
+
assert docstring.params[0].type_name is None
|
| 276 |
+
assert docstring.params[0].description == "description 1"
|
| 277 |
+
assert docstring.params[0].default is None
|
| 278 |
+
assert not docstring.params[0].is_optional
|
| 279 |
+
assert docstring.params[1].arg_name == "priority"
|
| 280 |
+
assert docstring.params[1].type_name == "int"
|
| 281 |
+
assert docstring.params[1].description == "description 2"
|
| 282 |
+
assert not docstring.params[1].is_optional
|
| 283 |
+
assert docstring.params[1].default is None
|
| 284 |
+
assert docstring.params[2].arg_name == "sender"
|
| 285 |
+
assert docstring.params[2].type_name == "str"
|
| 286 |
+
assert docstring.params[2].description == "description 3"
|
| 287 |
+
assert docstring.params[2].is_optional
|
| 288 |
+
assert docstring.params[2].default is None
|
| 289 |
+
assert docstring.params[3].arg_name == "message"
|
| 290 |
+
assert docstring.params[3].type_name == "str"
|
| 291 |
+
assert (
|
| 292 |
+
docstring.params[3].description == "description 4, defaults to 'hello'"
|
| 293 |
+
)
|
| 294 |
+
assert docstring.params[3].is_optional
|
| 295 |
+
assert docstring.params[3].default == "'hello'"
|
| 296 |
+
assert docstring.params[4].arg_name == "multiline"
|
| 297 |
+
assert docstring.params[4].type_name == "str"
|
| 298 |
+
assert (
|
| 299 |
+
docstring.params[4].description
|
| 300 |
+
== "long description 5,\ndefaults to 'bye'"
|
| 301 |
+
)
|
| 302 |
+
assert docstring.params[4].is_optional
|
| 303 |
+
assert docstring.params[4].default == "'bye'"
|
| 304 |
+
|
| 305 |
+
|
| 306 |
+
def test_returns() -> None:
|
| 307 |
+
"""Test parsing returns."""
|
| 308 |
+
docstring = parse(
|
| 309 |
+
"""
|
| 310 |
+
Short description
|
| 311 |
+
"""
|
| 312 |
+
)
|
| 313 |
+
assert docstring.returns is None
|
| 314 |
+
|
| 315 |
+
docstring = parse(
|
| 316 |
+
"""
|
| 317 |
+
Short description
|
| 318 |
+
@return: description
|
| 319 |
+
"""
|
| 320 |
+
)
|
| 321 |
+
assert docstring.returns is not None
|
| 322 |
+
assert docstring.returns.type_name is None
|
| 323 |
+
assert docstring.returns.description == "description"
|
| 324 |
+
assert not docstring.returns.is_generator
|
| 325 |
+
|
| 326 |
+
docstring = parse(
|
| 327 |
+
"""
|
| 328 |
+
Short description
|
| 329 |
+
@return: description
|
| 330 |
+
@rtype: int
|
| 331 |
+
"""
|
| 332 |
+
)
|
| 333 |
+
assert docstring.returns is not None
|
| 334 |
+
assert docstring.returns.type_name == "int"
|
| 335 |
+
assert docstring.returns.description == "description"
|
| 336 |
+
assert not docstring.returns.is_generator
|
| 337 |
+
|
| 338 |
+
|
| 339 |
+
def test_yields() -> None:
|
| 340 |
+
"""Test parsing yields."""
|
| 341 |
+
docstring = parse(
|
| 342 |
+
"""
|
| 343 |
+
Short description
|
| 344 |
+
"""
|
| 345 |
+
)
|
| 346 |
+
assert docstring.returns is None
|
| 347 |
+
|
| 348 |
+
docstring = parse(
|
| 349 |
+
"""
|
| 350 |
+
Short description
|
| 351 |
+
@yield: description
|
| 352 |
+
"""
|
| 353 |
+
)
|
| 354 |
+
assert docstring.returns is not None
|
| 355 |
+
assert docstring.returns.type_name is None
|
| 356 |
+
assert docstring.returns.description == "description"
|
| 357 |
+
assert docstring.returns.is_generator
|
| 358 |
+
|
| 359 |
+
docstring = parse(
|
| 360 |
+
"""
|
| 361 |
+
Short description
|
| 362 |
+
@yield: description
|
| 363 |
+
@ytype: int
|
| 364 |
+
"""
|
| 365 |
+
)
|
| 366 |
+
assert docstring.returns is not None
|
| 367 |
+
assert docstring.returns.type_name == "int"
|
| 368 |
+
assert docstring.returns.description == "description"
|
| 369 |
+
assert docstring.returns.is_generator
|
| 370 |
+
|
| 371 |
+
|
| 372 |
+
def test_raises() -> None:
|
| 373 |
+
"""Test parsing raises."""
|
| 374 |
+
docstring = parse(
|
| 375 |
+
"""
|
| 376 |
+
Short description
|
| 377 |
+
"""
|
| 378 |
+
)
|
| 379 |
+
assert len(docstring.raises) == 0
|
| 380 |
+
|
| 381 |
+
docstring = parse(
|
| 382 |
+
"""
|
| 383 |
+
Short description
|
| 384 |
+
@raise: description
|
| 385 |
+
"""
|
| 386 |
+
)
|
| 387 |
+
assert len(docstring.raises) == 1
|
| 388 |
+
assert docstring.raises[0].type_name is None
|
| 389 |
+
assert docstring.raises[0].description == "description"
|
| 390 |
+
|
| 391 |
+
docstring = parse(
|
| 392 |
+
"""
|
| 393 |
+
Short description
|
| 394 |
+
@raise ValueError: description
|
| 395 |
+
"""
|
| 396 |
+
)
|
| 397 |
+
assert len(docstring.raises) == 1
|
| 398 |
+
assert docstring.raises[0].type_name == "ValueError"
|
| 399 |
+
assert docstring.raises[0].description == "description"
|
| 400 |
+
|
| 401 |
+
|
| 402 |
+
def test_broken_meta() -> None:
|
| 403 |
+
"""Test parsing broken meta."""
|
| 404 |
+
with pytest.raises(ParseError):
|
| 405 |
+
parse("@")
|
| 406 |
+
|
| 407 |
+
with pytest.raises(ParseError):
|
| 408 |
+
parse("@param herp derp")
|
| 409 |
+
|
| 410 |
+
with pytest.raises(ParseError):
|
| 411 |
+
parse("@param: invalid")
|
| 412 |
+
|
| 413 |
+
with pytest.raises(ParseError):
|
| 414 |
+
parse("@param with too many args: desc")
|
| 415 |
+
|
| 416 |
+
# these should not raise any errors
|
| 417 |
+
parse("@sthstrange: desc")
|
| 418 |
+
|
| 419 |
+
|
| 420 |
+
@pytest.mark.parametrize(
|
| 421 |
+
"source, expected",
|
| 422 |
+
[
|
| 423 |
+
("", ""),
|
| 424 |
+
("\n", ""),
|
| 425 |
+
("Short description", "Short description"),
|
| 426 |
+
("\nShort description\n", "Short description"),
|
| 427 |
+
("\n Short description\n", "Short description"),
|
| 428 |
+
(
|
| 429 |
+
"Short description\n\nLong description",
|
| 430 |
+
"Short description\n\nLong description",
|
| 431 |
+
),
|
| 432 |
+
(
|
| 433 |
+
"""
|
| 434 |
+
Short description
|
| 435 |
+
|
| 436 |
+
Long description
|
| 437 |
+
""",
|
| 438 |
+
"Short description\n\nLong description",
|
| 439 |
+
),
|
| 440 |
+
(
|
| 441 |
+
"""
|
| 442 |
+
Short description
|
| 443 |
+
|
| 444 |
+
Long description
|
| 445 |
+
Second line
|
| 446 |
+
""",
|
| 447 |
+
"Short description\n\nLong description\nSecond line",
|
| 448 |
+
),
|
| 449 |
+
(
|
| 450 |
+
"Short description\nLong description",
|
| 451 |
+
"Short description\nLong description",
|
| 452 |
+
),
|
| 453 |
+
(
|
| 454 |
+
"""
|
| 455 |
+
Short description
|
| 456 |
+
Long description
|
| 457 |
+
""",
|
| 458 |
+
"Short description\nLong description",
|
| 459 |
+
),
|
| 460 |
+
(
|
| 461 |
+
"\nShort description\nLong description\n",
|
| 462 |
+
"Short description\nLong description",
|
| 463 |
+
),
|
| 464 |
+
(
|
| 465 |
+
"""
|
| 466 |
+
Short description
|
| 467 |
+
Long description
|
| 468 |
+
Second line
|
| 469 |
+
""",
|
| 470 |
+
"Short description\nLong description\nSecond line",
|
| 471 |
+
),
|
| 472 |
+
(
|
| 473 |
+
"""
|
| 474 |
+
Short description
|
| 475 |
+
@meta: asd
|
| 476 |
+
""",
|
| 477 |
+
"Short description\n@meta: asd",
|
| 478 |
+
),
|
| 479 |
+
(
|
| 480 |
+
"""
|
| 481 |
+
Short description
|
| 482 |
+
Long description
|
| 483 |
+
@meta: asd
|
| 484 |
+
""",
|
| 485 |
+
"Short description\nLong description\n@meta: asd",
|
| 486 |
+
),
|
| 487 |
+
(
|
| 488 |
+
"""
|
| 489 |
+
Short description
|
| 490 |
+
First line
|
| 491 |
+
Second line
|
| 492 |
+
@meta: asd
|
| 493 |
+
""",
|
| 494 |
+
"Short description\nFirst line\n Second line\n@meta: asd",
|
| 495 |
+
),
|
| 496 |
+
(
|
| 497 |
+
"""
|
| 498 |
+
Short description
|
| 499 |
+
|
| 500 |
+
First line
|
| 501 |
+
Second line
|
| 502 |
+
@meta: asd
|
| 503 |
+
""",
|
| 504 |
+
"Short description\n"
|
| 505 |
+
"\n"
|
| 506 |
+
"First line\n"
|
| 507 |
+
" Second line\n"
|
| 508 |
+
"@meta: asd",
|
| 509 |
+
),
|
| 510 |
+
(
|
| 511 |
+
"""
|
| 512 |
+
Short description
|
| 513 |
+
|
| 514 |
+
First line
|
| 515 |
+
Second line
|
| 516 |
+
|
| 517 |
+
@meta: asd
|
| 518 |
+
""",
|
| 519 |
+
"Short description\n"
|
| 520 |
+
"\n"
|
| 521 |
+
"First line\n"
|
| 522 |
+
" Second line\n"
|
| 523 |
+
"\n"
|
| 524 |
+
"@meta: asd",
|
| 525 |
+
),
|
| 526 |
+
(
|
| 527 |
+
"""
|
| 528 |
+
@meta: asd
|
| 529 |
+
""",
|
| 530 |
+
"@meta: asd",
|
| 531 |
+
),
|
| 532 |
+
(
|
| 533 |
+
"""
|
| 534 |
+
Short description
|
| 535 |
+
|
| 536 |
+
@meta: asd
|
| 537 |
+
1
|
| 538 |
+
2
|
| 539 |
+
3
|
| 540 |
+
""",
|
| 541 |
+
"Short description\n"
|
| 542 |
+
"\n"
|
| 543 |
+
"@meta: asd\n"
|
| 544 |
+
" 1\n"
|
| 545 |
+
" 2\n"
|
| 546 |
+
" 3",
|
| 547 |
+
),
|
| 548 |
+
(
|
| 549 |
+
"""
|
| 550 |
+
Short description
|
| 551 |
+
|
| 552 |
+
@meta1: asd
|
| 553 |
+
1
|
| 554 |
+
2
|
| 555 |
+
3
|
| 556 |
+
@meta2: herp
|
| 557 |
+
@meta3: derp
|
| 558 |
+
""",
|
| 559 |
+
"Short description\n"
|
| 560 |
+
"\n@meta1: asd\n"
|
| 561 |
+
" 1\n"
|
| 562 |
+
" 2\n"
|
| 563 |
+
" 3\n@meta2: herp\n"
|
| 564 |
+
"@meta3: derp",
|
| 565 |
+
),
|
| 566 |
+
(
|
| 567 |
+
"""
|
| 568 |
+
Short description
|
| 569 |
+
|
| 570 |
+
@meta ene due rabe: asd
|
| 571 |
+
""",
|
| 572 |
+
"Short description\n\n@meta ene due rabe: asd",
|
| 573 |
+
),
|
| 574 |
+
(
|
| 575 |
+
"""
|
| 576 |
+
Short description
|
| 577 |
+
|
| 578 |
+
@param name: description 1
|
| 579 |
+
@param priority: description 2
|
| 580 |
+
@type priority: int
|
| 581 |
+
@param sender: description 3
|
| 582 |
+
@type sender: str?
|
| 583 |
+
@type message: str?
|
| 584 |
+
@param message: description 4, defaults to 'hello'
|
| 585 |
+
@type multiline: str?
|
| 586 |
+
@param multiline: long description 5,
|
| 587 |
+
defaults to 'bye'
|
| 588 |
+
""",
|
| 589 |
+
"Short description\n"
|
| 590 |
+
"\n"
|
| 591 |
+
"@param name: description 1\n"
|
| 592 |
+
"@type priority: int\n"
|
| 593 |
+
"@param priority: description 2\n"
|
| 594 |
+
"@type sender: str?\n"
|
| 595 |
+
"@param sender: description 3\n"
|
| 596 |
+
"@type message: str?\n"
|
| 597 |
+
"@param message: description 4, defaults to 'hello'\n"
|
| 598 |
+
"@type multiline: str?\n"
|
| 599 |
+
"@param multiline: long description 5,\n"
|
| 600 |
+
" defaults to 'bye'",
|
| 601 |
+
),
|
| 602 |
+
(
|
| 603 |
+
"""
|
| 604 |
+
Short description
|
| 605 |
+
@raise: description
|
| 606 |
+
""",
|
| 607 |
+
"Short description\n@raise: description",
|
| 608 |
+
),
|
| 609 |
+
(
|
| 610 |
+
"""
|
| 611 |
+
Short description
|
| 612 |
+
@raise ValueError: description
|
| 613 |
+
""",
|
| 614 |
+
"Short description\n@raise ValueError: description",
|
| 615 |
+
),
|
| 616 |
+
],
|
| 617 |
+
)
|
| 618 |
+
def test_compose(source: str, expected: str) -> None:
|
| 619 |
+
"""Test compose in default mode."""
|
| 620 |
+
assert compose(parse(source)) == expected
|
| 621 |
+
|
| 622 |
+
|
| 623 |
+
@pytest.mark.parametrize(
|
| 624 |
+
"source, expected",
|
| 625 |
+
[
|
| 626 |
+
(
|
| 627 |
+
"""
|
| 628 |
+
Short description
|
| 629 |
+
|
| 630 |
+
@param name: description 1
|
| 631 |
+
@param priority: description 2
|
| 632 |
+
@type priority: int
|
| 633 |
+
@param sender: description 3
|
| 634 |
+
@type sender: str?
|
| 635 |
+
@type message: str?
|
| 636 |
+
@param message: description 4, defaults to 'hello'
|
| 637 |
+
@type multiline: str?
|
| 638 |
+
@param multiline: long description 5,
|
| 639 |
+
defaults to 'bye'
|
| 640 |
+
""",
|
| 641 |
+
"Short description\n"
|
| 642 |
+
"\n"
|
| 643 |
+
"@param name:\n"
|
| 644 |
+
" description 1\n"
|
| 645 |
+
"@type priority: int\n"
|
| 646 |
+
"@param priority:\n"
|
| 647 |
+
" description 2\n"
|
| 648 |
+
"@type sender: str?\n"
|
| 649 |
+
"@param sender:\n"
|
| 650 |
+
" description 3\n"
|
| 651 |
+
"@type message: str?\n"
|
| 652 |
+
"@param message:\n"
|
| 653 |
+
" description 4, defaults to 'hello'\n"
|
| 654 |
+
"@type multiline: str?\n"
|
| 655 |
+
"@param multiline:\n"
|
| 656 |
+
" long description 5,\n"
|
| 657 |
+
" defaults to 'bye'",
|
| 658 |
+
),
|
| 659 |
+
],
|
| 660 |
+
)
|
| 661 |
+
def test_compose_clean(source: str, expected: str) -> None:
|
| 662 |
+
"""Test compose in clean mode."""
|
| 663 |
+
assert (
|
| 664 |
+
compose(parse(source), rendering_style=RenderingStyle.CLEAN)
|
| 665 |
+
== expected
|
| 666 |
+
)
|
| 667 |
+
|
| 668 |
+
|
| 669 |
+
@pytest.mark.parametrize(
|
| 670 |
+
"source, expected",
|
| 671 |
+
[
|
| 672 |
+
(
|
| 673 |
+
"""
|
| 674 |
+
Short description
|
| 675 |
+
|
| 676 |
+
@param name: description 1
|
| 677 |
+
@param priority: description 2
|
| 678 |
+
@type priority: int
|
| 679 |
+
@param sender: description 3
|
| 680 |
+
@type sender: str?
|
| 681 |
+
@type message: str?
|
| 682 |
+
@param message: description 4, defaults to 'hello'
|
| 683 |
+
@type multiline: str?
|
| 684 |
+
@param multiline: long description 5,
|
| 685 |
+
defaults to 'bye'
|
| 686 |
+
""",
|
| 687 |
+
"Short description\n"
|
| 688 |
+
"\n"
|
| 689 |
+
"@param name:\n"
|
| 690 |
+
" description 1\n"
|
| 691 |
+
"@type priority:\n"
|
| 692 |
+
" int\n"
|
| 693 |
+
"@param priority:\n"
|
| 694 |
+
" description 2\n"
|
| 695 |
+
"@type sender:\n"
|
| 696 |
+
" str?\n"
|
| 697 |
+
"@param sender:\n"
|
| 698 |
+
" description 3\n"
|
| 699 |
+
"@type message:\n"
|
| 700 |
+
" str?\n"
|
| 701 |
+
"@param message:\n"
|
| 702 |
+
" description 4, defaults to 'hello'\n"
|
| 703 |
+
"@type multiline:\n"
|
| 704 |
+
" str?\n"
|
| 705 |
+
"@param multiline:\n"
|
| 706 |
+
" long description 5,\n"
|
| 707 |
+
" defaults to 'bye'",
|
| 708 |
+
),
|
| 709 |
+
],
|
| 710 |
+
)
|
| 711 |
+
def test_compose_expanded(source: str, expected: str) -> None:
|
| 712 |
+
"""Test compose in expanded mode."""
|
| 713 |
+
assert (
|
| 714 |
+
compose(parse(source), rendering_style=RenderingStyle.EXPANDED)
|
| 715 |
+
== expected
|
| 716 |
+
)
|
| 717 |
+
|
| 718 |
+
|
| 719 |
+
def test_short_rtype() -> None:
|
| 720 |
+
"""Test abbreviated docstring with only return type information."""
|
| 721 |
+
string = "Short description.\n\n@rtype: float"
|
| 722 |
+
docstring = parse(string)
|
| 723 |
+
assert compose(docstring) == string
|
parrot/lib/python3.10/site-packages/docstring_parser/tests/test_google.py
ADDED
|
@@ -0,0 +1,977 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for Google-style docstring routines."""
|
| 2 |
+
import typing as T
|
| 3 |
+
|
| 4 |
+
import pytest
|
| 5 |
+
from docstring_parser.common import ParseError, RenderingStyle
|
| 6 |
+
from docstring_parser.google import (
|
| 7 |
+
GoogleParser,
|
| 8 |
+
Section,
|
| 9 |
+
SectionType,
|
| 10 |
+
compose,
|
| 11 |
+
parse,
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def test_google_parser_unknown_section() -> None:
|
| 16 |
+
"""Test parsing an unknown section with default GoogleParser
|
| 17 |
+
configuration.
|
| 18 |
+
"""
|
| 19 |
+
parser = GoogleParser()
|
| 20 |
+
docstring = parser.parse(
|
| 21 |
+
"""
|
| 22 |
+
Unknown:
|
| 23 |
+
spam: a
|
| 24 |
+
"""
|
| 25 |
+
)
|
| 26 |
+
assert docstring.short_description == "Unknown:"
|
| 27 |
+
assert docstring.long_description == "spam: a"
|
| 28 |
+
assert len(docstring.meta) == 0
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def test_google_parser_custom_sections() -> None:
|
| 32 |
+
"""Test parsing an unknown section with custom GoogleParser
|
| 33 |
+
configuration.
|
| 34 |
+
"""
|
| 35 |
+
parser = GoogleParser(
|
| 36 |
+
[
|
| 37 |
+
Section("DESCRIPTION", "desc", SectionType.SINGULAR),
|
| 38 |
+
Section("ARGUMENTS", "param", SectionType.MULTIPLE),
|
| 39 |
+
Section("ATTRIBUTES", "attribute", SectionType.MULTIPLE),
|
| 40 |
+
Section("EXAMPLES", "examples", SectionType.SINGULAR),
|
| 41 |
+
],
|
| 42 |
+
title_colon=False,
|
| 43 |
+
)
|
| 44 |
+
docstring = parser.parse(
|
| 45 |
+
"""
|
| 46 |
+
DESCRIPTION
|
| 47 |
+
This is the description.
|
| 48 |
+
|
| 49 |
+
ARGUMENTS
|
| 50 |
+
arg1: first arg
|
| 51 |
+
arg2: second arg
|
| 52 |
+
|
| 53 |
+
ATTRIBUTES
|
| 54 |
+
attr1: first attribute
|
| 55 |
+
attr2: second attribute
|
| 56 |
+
|
| 57 |
+
EXAMPLES
|
| 58 |
+
Many examples
|
| 59 |
+
More examples
|
| 60 |
+
"""
|
| 61 |
+
)
|
| 62 |
+
|
| 63 |
+
assert docstring.short_description is None
|
| 64 |
+
assert docstring.long_description is None
|
| 65 |
+
assert len(docstring.meta) == 6
|
| 66 |
+
assert docstring.meta[0].args == ["desc"]
|
| 67 |
+
assert docstring.meta[0].description == "This is the description."
|
| 68 |
+
assert docstring.meta[1].args == ["param", "arg1"]
|
| 69 |
+
assert docstring.meta[1].description == "first arg"
|
| 70 |
+
assert docstring.meta[2].args == ["param", "arg2"]
|
| 71 |
+
assert docstring.meta[2].description == "second arg"
|
| 72 |
+
assert docstring.meta[3].args == ["attribute", "attr1"]
|
| 73 |
+
assert docstring.meta[3].description == "first attribute"
|
| 74 |
+
assert docstring.meta[4].args == ["attribute", "attr2"]
|
| 75 |
+
assert docstring.meta[4].description == "second attribute"
|
| 76 |
+
assert docstring.meta[5].args == ["examples"]
|
| 77 |
+
assert docstring.meta[5].description == "Many examples\nMore examples"
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def test_google_parser_custom_sections_after() -> None:
|
| 81 |
+
"""Test parsing an unknown section with custom GoogleParser configuration
|
| 82 |
+
that was set at a runtime.
|
| 83 |
+
"""
|
| 84 |
+
parser = GoogleParser(title_colon=False)
|
| 85 |
+
parser.add_section(Section("Note", "note", SectionType.SINGULAR))
|
| 86 |
+
docstring = parser.parse(
|
| 87 |
+
"""
|
| 88 |
+
short description
|
| 89 |
+
|
| 90 |
+
Note:
|
| 91 |
+
a note
|
| 92 |
+
"""
|
| 93 |
+
)
|
| 94 |
+
assert docstring.short_description == "short description"
|
| 95 |
+
assert docstring.long_description == "Note:\n a note"
|
| 96 |
+
|
| 97 |
+
docstring = parser.parse(
|
| 98 |
+
"""
|
| 99 |
+
short description
|
| 100 |
+
|
| 101 |
+
Note a note
|
| 102 |
+
"""
|
| 103 |
+
)
|
| 104 |
+
assert docstring.short_description == "short description"
|
| 105 |
+
assert docstring.long_description == "Note a note"
|
| 106 |
+
|
| 107 |
+
docstring = parser.parse(
|
| 108 |
+
"""
|
| 109 |
+
short description
|
| 110 |
+
|
| 111 |
+
Note
|
| 112 |
+
a note
|
| 113 |
+
"""
|
| 114 |
+
)
|
| 115 |
+
assert len(docstring.meta) == 1
|
| 116 |
+
assert docstring.meta[0].args == ["note"]
|
| 117 |
+
assert docstring.meta[0].description == "a note"
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
@pytest.mark.parametrize(
|
| 121 |
+
"source, expected",
|
| 122 |
+
[
|
| 123 |
+
("", None),
|
| 124 |
+
("\n", None),
|
| 125 |
+
("Short description", "Short description"),
|
| 126 |
+
("\nShort description\n", "Short description"),
|
| 127 |
+
("\n Short description\n", "Short description"),
|
| 128 |
+
],
|
| 129 |
+
)
|
| 130 |
+
def test_short_description(source: str, expected: str) -> None:
|
| 131 |
+
"""Test parsing short description."""
|
| 132 |
+
docstring = parse(source)
|
| 133 |
+
assert docstring.short_description == expected
|
| 134 |
+
assert docstring.long_description is None
|
| 135 |
+
assert not docstring.meta
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
@pytest.mark.parametrize(
|
| 139 |
+
"source, expected_short_desc, expected_long_desc, expected_blank",
|
| 140 |
+
[
|
| 141 |
+
(
|
| 142 |
+
"Short description\n\nLong description",
|
| 143 |
+
"Short description",
|
| 144 |
+
"Long description",
|
| 145 |
+
True,
|
| 146 |
+
),
|
| 147 |
+
(
|
| 148 |
+
"""
|
| 149 |
+
Short description
|
| 150 |
+
|
| 151 |
+
Long description
|
| 152 |
+
""",
|
| 153 |
+
"Short description",
|
| 154 |
+
"Long description",
|
| 155 |
+
True,
|
| 156 |
+
),
|
| 157 |
+
(
|
| 158 |
+
"""
|
| 159 |
+
Short description
|
| 160 |
+
|
| 161 |
+
Long description
|
| 162 |
+
Second line
|
| 163 |
+
""",
|
| 164 |
+
"Short description",
|
| 165 |
+
"Long description\nSecond line",
|
| 166 |
+
True,
|
| 167 |
+
),
|
| 168 |
+
(
|
| 169 |
+
"Short description\nLong description",
|
| 170 |
+
"Short description",
|
| 171 |
+
"Long description",
|
| 172 |
+
False,
|
| 173 |
+
),
|
| 174 |
+
(
|
| 175 |
+
"""
|
| 176 |
+
Short description
|
| 177 |
+
Long description
|
| 178 |
+
""",
|
| 179 |
+
"Short description",
|
| 180 |
+
"Long description",
|
| 181 |
+
False,
|
| 182 |
+
),
|
| 183 |
+
(
|
| 184 |
+
"\nShort description\nLong description\n",
|
| 185 |
+
"Short description",
|
| 186 |
+
"Long description",
|
| 187 |
+
False,
|
| 188 |
+
),
|
| 189 |
+
(
|
| 190 |
+
"""
|
| 191 |
+
Short description
|
| 192 |
+
Long description
|
| 193 |
+
Second line
|
| 194 |
+
""",
|
| 195 |
+
"Short description",
|
| 196 |
+
"Long description\nSecond line",
|
| 197 |
+
False,
|
| 198 |
+
),
|
| 199 |
+
],
|
| 200 |
+
)
|
| 201 |
+
def test_long_description(
|
| 202 |
+
source: str,
|
| 203 |
+
expected_short_desc: str,
|
| 204 |
+
expected_long_desc: str,
|
| 205 |
+
expected_blank: bool,
|
| 206 |
+
) -> None:
|
| 207 |
+
"""Test parsing long description."""
|
| 208 |
+
docstring = parse(source)
|
| 209 |
+
assert docstring.short_description == expected_short_desc
|
| 210 |
+
assert docstring.long_description == expected_long_desc
|
| 211 |
+
assert docstring.blank_after_short_description == expected_blank
|
| 212 |
+
assert not docstring.meta
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
@pytest.mark.parametrize(
|
| 216 |
+
"source, expected_short_desc, expected_long_desc, "
|
| 217 |
+
"expected_blank_short_desc, expected_blank_long_desc",
|
| 218 |
+
[
|
| 219 |
+
(
|
| 220 |
+
"""
|
| 221 |
+
Short description
|
| 222 |
+
Args:
|
| 223 |
+
asd:
|
| 224 |
+
""",
|
| 225 |
+
"Short description",
|
| 226 |
+
None,
|
| 227 |
+
False,
|
| 228 |
+
False,
|
| 229 |
+
),
|
| 230 |
+
(
|
| 231 |
+
"""
|
| 232 |
+
Short description
|
| 233 |
+
Long description
|
| 234 |
+
Args:
|
| 235 |
+
asd:
|
| 236 |
+
""",
|
| 237 |
+
"Short description",
|
| 238 |
+
"Long description",
|
| 239 |
+
False,
|
| 240 |
+
False,
|
| 241 |
+
),
|
| 242 |
+
(
|
| 243 |
+
"""
|
| 244 |
+
Short description
|
| 245 |
+
First line
|
| 246 |
+
Second line
|
| 247 |
+
Args:
|
| 248 |
+
asd:
|
| 249 |
+
""",
|
| 250 |
+
"Short description",
|
| 251 |
+
"First line\n Second line",
|
| 252 |
+
False,
|
| 253 |
+
False,
|
| 254 |
+
),
|
| 255 |
+
(
|
| 256 |
+
"""
|
| 257 |
+
Short description
|
| 258 |
+
|
| 259 |
+
First line
|
| 260 |
+
Second line
|
| 261 |
+
Args:
|
| 262 |
+
asd:
|
| 263 |
+
""",
|
| 264 |
+
"Short description",
|
| 265 |
+
"First line\n Second line",
|
| 266 |
+
True,
|
| 267 |
+
False,
|
| 268 |
+
),
|
| 269 |
+
(
|
| 270 |
+
"""
|
| 271 |
+
Short description
|
| 272 |
+
|
| 273 |
+
First line
|
| 274 |
+
Second line
|
| 275 |
+
|
| 276 |
+
Args:
|
| 277 |
+
asd:
|
| 278 |
+
""",
|
| 279 |
+
"Short description",
|
| 280 |
+
"First line\n Second line",
|
| 281 |
+
True,
|
| 282 |
+
True,
|
| 283 |
+
),
|
| 284 |
+
(
|
| 285 |
+
"""
|
| 286 |
+
Args:
|
| 287 |
+
asd:
|
| 288 |
+
""",
|
| 289 |
+
None,
|
| 290 |
+
None,
|
| 291 |
+
False,
|
| 292 |
+
False,
|
| 293 |
+
),
|
| 294 |
+
],
|
| 295 |
+
)
|
| 296 |
+
def test_meta_newlines(
|
| 297 |
+
source: str,
|
| 298 |
+
expected_short_desc: T.Optional[str],
|
| 299 |
+
expected_long_desc: T.Optional[str],
|
| 300 |
+
expected_blank_short_desc: bool,
|
| 301 |
+
expected_blank_long_desc: bool,
|
| 302 |
+
) -> None:
|
| 303 |
+
"""Test parsing newlines around description sections."""
|
| 304 |
+
docstring = parse(source)
|
| 305 |
+
assert docstring.short_description == expected_short_desc
|
| 306 |
+
assert docstring.long_description == expected_long_desc
|
| 307 |
+
assert docstring.blank_after_short_description == expected_blank_short_desc
|
| 308 |
+
assert docstring.blank_after_long_description == expected_blank_long_desc
|
| 309 |
+
assert len(docstring.meta) == 1
|
| 310 |
+
|
| 311 |
+
|
| 312 |
+
def test_meta_with_multiline_description() -> None:
|
| 313 |
+
"""Test parsing multiline meta documentation."""
|
| 314 |
+
docstring = parse(
|
| 315 |
+
"""
|
| 316 |
+
Short description
|
| 317 |
+
|
| 318 |
+
Args:
|
| 319 |
+
spam: asd
|
| 320 |
+
1
|
| 321 |
+
2
|
| 322 |
+
3
|
| 323 |
+
"""
|
| 324 |
+
)
|
| 325 |
+
assert docstring.short_description == "Short description"
|
| 326 |
+
assert len(docstring.meta) == 1
|
| 327 |
+
assert docstring.meta[0].args == ["param", "spam"]
|
| 328 |
+
assert docstring.meta[0].arg_name == "spam"
|
| 329 |
+
assert docstring.meta[0].description == "asd\n1\n 2\n3"
|
| 330 |
+
|
| 331 |
+
|
| 332 |
+
def test_default_args() -> None:
|
| 333 |
+
"""Test parsing default arguments."""
|
| 334 |
+
docstring = parse(
|
| 335 |
+
"""A sample function
|
| 336 |
+
|
| 337 |
+
A function the demonstrates docstrings
|
| 338 |
+
|
| 339 |
+
Args:
|
| 340 |
+
arg1 (int): The firsty arg
|
| 341 |
+
arg2 (str): The second arg
|
| 342 |
+
arg3 (float, optional): The third arg. Defaults to 1.0.
|
| 343 |
+
arg4 (Optional[Dict[str, Any]], optional): The last arg. Defaults to None.
|
| 344 |
+
arg5 (str, optional): The fifth arg. Defaults to DEFAULT_ARG5.
|
| 345 |
+
|
| 346 |
+
Returns:
|
| 347 |
+
Mapping[str, Any]: The args packed in a mapping
|
| 348 |
+
"""
|
| 349 |
+
)
|
| 350 |
+
assert docstring is not None
|
| 351 |
+
assert len(docstring.params) == 5
|
| 352 |
+
|
| 353 |
+
arg4 = docstring.params[3]
|
| 354 |
+
assert arg4.arg_name == "arg4"
|
| 355 |
+
assert arg4.is_optional
|
| 356 |
+
assert arg4.type_name == "Optional[Dict[str, Any]]"
|
| 357 |
+
assert arg4.default == "None"
|
| 358 |
+
assert arg4.description == "The last arg. Defaults to None."
|
| 359 |
+
|
| 360 |
+
|
| 361 |
+
def test_multiple_meta() -> None:
|
| 362 |
+
"""Test parsing multiple meta."""
|
| 363 |
+
docstring = parse(
|
| 364 |
+
"""
|
| 365 |
+
Short description
|
| 366 |
+
|
| 367 |
+
Args:
|
| 368 |
+
spam: asd
|
| 369 |
+
1
|
| 370 |
+
2
|
| 371 |
+
3
|
| 372 |
+
|
| 373 |
+
Raises:
|
| 374 |
+
bla: herp
|
| 375 |
+
yay: derp
|
| 376 |
+
"""
|
| 377 |
+
)
|
| 378 |
+
assert docstring.short_description == "Short description"
|
| 379 |
+
assert len(docstring.meta) == 3
|
| 380 |
+
assert docstring.meta[0].args == ["param", "spam"]
|
| 381 |
+
assert docstring.meta[0].arg_name == "spam"
|
| 382 |
+
assert docstring.meta[0].description == "asd\n1\n 2\n3"
|
| 383 |
+
assert docstring.meta[1].args == ["raises", "bla"]
|
| 384 |
+
assert docstring.meta[1].type_name == "bla"
|
| 385 |
+
assert docstring.meta[1].description == "herp"
|
| 386 |
+
assert docstring.meta[2].args == ["raises", "yay"]
|
| 387 |
+
assert docstring.meta[2].type_name == "yay"
|
| 388 |
+
assert docstring.meta[2].description == "derp"
|
| 389 |
+
|
| 390 |
+
|
| 391 |
+
def test_params() -> None:
|
| 392 |
+
"""Test parsing params."""
|
| 393 |
+
docstring = parse("Short description")
|
| 394 |
+
assert len(docstring.params) == 0
|
| 395 |
+
|
| 396 |
+
docstring = parse(
|
| 397 |
+
"""
|
| 398 |
+
Short description
|
| 399 |
+
|
| 400 |
+
Args:
|
| 401 |
+
name: description 1
|
| 402 |
+
priority (int): description 2
|
| 403 |
+
sender (str?): description 3
|
| 404 |
+
ratio (Optional[float], optional): description 4
|
| 405 |
+
"""
|
| 406 |
+
)
|
| 407 |
+
assert len(docstring.params) == 4
|
| 408 |
+
assert docstring.params[0].arg_name == "name"
|
| 409 |
+
assert docstring.params[0].type_name is None
|
| 410 |
+
assert docstring.params[0].description == "description 1"
|
| 411 |
+
assert not docstring.params[0].is_optional
|
| 412 |
+
assert docstring.params[1].arg_name == "priority"
|
| 413 |
+
assert docstring.params[1].type_name == "int"
|
| 414 |
+
assert docstring.params[1].description == "description 2"
|
| 415 |
+
assert not docstring.params[1].is_optional
|
| 416 |
+
assert docstring.params[2].arg_name == "sender"
|
| 417 |
+
assert docstring.params[2].type_name == "str"
|
| 418 |
+
assert docstring.params[2].description == "description 3"
|
| 419 |
+
assert docstring.params[2].is_optional
|
| 420 |
+
assert docstring.params[3].arg_name == "ratio"
|
| 421 |
+
assert docstring.params[3].type_name == "Optional[float]"
|
| 422 |
+
assert docstring.params[3].description == "description 4"
|
| 423 |
+
assert docstring.params[3].is_optional
|
| 424 |
+
|
| 425 |
+
docstring = parse(
|
| 426 |
+
"""
|
| 427 |
+
Short description
|
| 428 |
+
|
| 429 |
+
Args:
|
| 430 |
+
name: description 1
|
| 431 |
+
with multi-line text
|
| 432 |
+
priority (int): description 2
|
| 433 |
+
"""
|
| 434 |
+
)
|
| 435 |
+
assert len(docstring.params) == 2
|
| 436 |
+
assert docstring.params[0].arg_name == "name"
|
| 437 |
+
assert docstring.params[0].type_name is None
|
| 438 |
+
assert docstring.params[0].description == (
|
| 439 |
+
"description 1\nwith multi-line text"
|
| 440 |
+
)
|
| 441 |
+
assert docstring.params[1].arg_name == "priority"
|
| 442 |
+
assert docstring.params[1].type_name == "int"
|
| 443 |
+
assert docstring.params[1].description == "description 2"
|
| 444 |
+
|
| 445 |
+
|
| 446 |
+
def test_attributes() -> None:
|
| 447 |
+
"""Test parsing attributes."""
|
| 448 |
+
docstring = parse("Short description")
|
| 449 |
+
assert len(docstring.params) == 0
|
| 450 |
+
|
| 451 |
+
docstring = parse(
|
| 452 |
+
"""
|
| 453 |
+
Short description
|
| 454 |
+
|
| 455 |
+
Attributes:
|
| 456 |
+
name: description 1
|
| 457 |
+
priority (int): description 2
|
| 458 |
+
sender (str?): description 3
|
| 459 |
+
ratio (Optional[float], optional): description 4
|
| 460 |
+
"""
|
| 461 |
+
)
|
| 462 |
+
assert len(docstring.params) == 4
|
| 463 |
+
assert docstring.params[0].arg_name == "name"
|
| 464 |
+
assert docstring.params[0].type_name is None
|
| 465 |
+
assert docstring.params[0].description == "description 1"
|
| 466 |
+
assert not docstring.params[0].is_optional
|
| 467 |
+
assert docstring.params[1].arg_name == "priority"
|
| 468 |
+
assert docstring.params[1].type_name == "int"
|
| 469 |
+
assert docstring.params[1].description == "description 2"
|
| 470 |
+
assert not docstring.params[1].is_optional
|
| 471 |
+
assert docstring.params[2].arg_name == "sender"
|
| 472 |
+
assert docstring.params[2].type_name == "str"
|
| 473 |
+
assert docstring.params[2].description == "description 3"
|
| 474 |
+
assert docstring.params[2].is_optional
|
| 475 |
+
assert docstring.params[3].arg_name == "ratio"
|
| 476 |
+
assert docstring.params[3].type_name == "Optional[float]"
|
| 477 |
+
assert docstring.params[3].description == "description 4"
|
| 478 |
+
assert docstring.params[3].is_optional
|
| 479 |
+
|
| 480 |
+
docstring = parse(
|
| 481 |
+
"""
|
| 482 |
+
Short description
|
| 483 |
+
|
| 484 |
+
Attributes:
|
| 485 |
+
name: description 1
|
| 486 |
+
with multi-line text
|
| 487 |
+
priority (int): description 2
|
| 488 |
+
"""
|
| 489 |
+
)
|
| 490 |
+
assert len(docstring.params) == 2
|
| 491 |
+
assert docstring.params[0].arg_name == "name"
|
| 492 |
+
assert docstring.params[0].type_name is None
|
| 493 |
+
assert docstring.params[0].description == (
|
| 494 |
+
"description 1\nwith multi-line text"
|
| 495 |
+
)
|
| 496 |
+
assert docstring.params[1].arg_name == "priority"
|
| 497 |
+
assert docstring.params[1].type_name == "int"
|
| 498 |
+
assert docstring.params[1].description == "description 2"
|
| 499 |
+
|
| 500 |
+
|
| 501 |
+
def test_returns() -> None:
|
| 502 |
+
"""Test parsing returns."""
|
| 503 |
+
docstring = parse(
|
| 504 |
+
"""
|
| 505 |
+
Short description
|
| 506 |
+
"""
|
| 507 |
+
)
|
| 508 |
+
assert docstring.returns is None
|
| 509 |
+
assert docstring.many_returns is not None
|
| 510 |
+
assert len(docstring.many_returns) == 0
|
| 511 |
+
|
| 512 |
+
docstring = parse(
|
| 513 |
+
"""
|
| 514 |
+
Short description
|
| 515 |
+
Returns:
|
| 516 |
+
description
|
| 517 |
+
"""
|
| 518 |
+
)
|
| 519 |
+
assert docstring.returns is not None
|
| 520 |
+
assert docstring.returns.type_name is None
|
| 521 |
+
assert docstring.returns.description == "description"
|
| 522 |
+
assert docstring.many_returns is not None
|
| 523 |
+
assert len(docstring.many_returns) == 1
|
| 524 |
+
assert docstring.many_returns[0] == docstring.returns
|
| 525 |
+
|
| 526 |
+
docstring = parse(
|
| 527 |
+
"""
|
| 528 |
+
Short description
|
| 529 |
+
Returns:
|
| 530 |
+
description with: a colon!
|
| 531 |
+
"""
|
| 532 |
+
)
|
| 533 |
+
assert docstring.returns is not None
|
| 534 |
+
assert docstring.returns.type_name is None
|
| 535 |
+
assert docstring.returns.description == "description with: a colon!"
|
| 536 |
+
assert docstring.many_returns is not None
|
| 537 |
+
assert len(docstring.many_returns) == 1
|
| 538 |
+
assert docstring.many_returns[0] == docstring.returns
|
| 539 |
+
|
| 540 |
+
docstring = parse(
|
| 541 |
+
"""
|
| 542 |
+
Short description
|
| 543 |
+
Returns:
|
| 544 |
+
int: description
|
| 545 |
+
"""
|
| 546 |
+
)
|
| 547 |
+
assert docstring.returns is not None
|
| 548 |
+
assert docstring.returns.type_name == "int"
|
| 549 |
+
assert docstring.returns.description == "description"
|
| 550 |
+
assert docstring.many_returns is not None
|
| 551 |
+
assert len(docstring.many_returns) == 1
|
| 552 |
+
assert docstring.many_returns[0] == docstring.returns
|
| 553 |
+
|
| 554 |
+
docstring = parse(
|
| 555 |
+
"""
|
| 556 |
+
Returns:
|
| 557 |
+
Optional[Mapping[str, List[int]]]: A description: with a colon
|
| 558 |
+
"""
|
| 559 |
+
)
|
| 560 |
+
assert docstring.returns is not None
|
| 561 |
+
assert docstring.returns.type_name == "Optional[Mapping[str, List[int]]]"
|
| 562 |
+
assert docstring.returns.description == "A description: with a colon"
|
| 563 |
+
assert docstring.many_returns is not None
|
| 564 |
+
assert len(docstring.many_returns) == 1
|
| 565 |
+
assert docstring.many_returns[0] == docstring.returns
|
| 566 |
+
|
| 567 |
+
docstring = parse(
|
| 568 |
+
"""
|
| 569 |
+
Short description
|
| 570 |
+
Yields:
|
| 571 |
+
int: description
|
| 572 |
+
"""
|
| 573 |
+
)
|
| 574 |
+
assert docstring.returns is not None
|
| 575 |
+
assert docstring.returns.type_name == "int"
|
| 576 |
+
assert docstring.returns.description == "description"
|
| 577 |
+
assert docstring.many_returns is not None
|
| 578 |
+
assert len(docstring.many_returns) == 1
|
| 579 |
+
assert docstring.many_returns[0] == docstring.returns
|
| 580 |
+
|
| 581 |
+
docstring = parse(
|
| 582 |
+
"""
|
| 583 |
+
Short description
|
| 584 |
+
Returns:
|
| 585 |
+
int: description
|
| 586 |
+
with much text
|
| 587 |
+
|
| 588 |
+
even some spacing
|
| 589 |
+
"""
|
| 590 |
+
)
|
| 591 |
+
assert docstring.returns is not None
|
| 592 |
+
assert docstring.returns.type_name == "int"
|
| 593 |
+
assert docstring.returns.description == (
|
| 594 |
+
"description\nwith much text\n\neven some spacing"
|
| 595 |
+
)
|
| 596 |
+
assert docstring.many_returns is not None
|
| 597 |
+
assert len(docstring.many_returns) == 1
|
| 598 |
+
assert docstring.many_returns[0] == docstring.returns
|
| 599 |
+
|
| 600 |
+
|
| 601 |
+
def test_raises() -> None:
|
| 602 |
+
"""Test parsing raises."""
|
| 603 |
+
docstring = parse(
|
| 604 |
+
"""
|
| 605 |
+
Short description
|
| 606 |
+
"""
|
| 607 |
+
)
|
| 608 |
+
assert len(docstring.raises) == 0
|
| 609 |
+
|
| 610 |
+
docstring = parse(
|
| 611 |
+
"""
|
| 612 |
+
Short description
|
| 613 |
+
Raises:
|
| 614 |
+
ValueError: description
|
| 615 |
+
"""
|
| 616 |
+
)
|
| 617 |
+
assert len(docstring.raises) == 1
|
| 618 |
+
assert docstring.raises[0].type_name == "ValueError"
|
| 619 |
+
assert docstring.raises[0].description == "description"
|
| 620 |
+
|
| 621 |
+
|
| 622 |
+
def test_examples() -> None:
|
| 623 |
+
"""Test parsing examples."""
|
| 624 |
+
docstring = parse(
|
| 625 |
+
"""
|
| 626 |
+
Short description
|
| 627 |
+
Example:
|
| 628 |
+
example: 1
|
| 629 |
+
Examples:
|
| 630 |
+
long example
|
| 631 |
+
|
| 632 |
+
more here
|
| 633 |
+
"""
|
| 634 |
+
)
|
| 635 |
+
assert len(docstring.examples) == 2
|
| 636 |
+
assert docstring.examples[0].description == "example: 1"
|
| 637 |
+
assert docstring.examples[1].description == "long example\n\nmore here"
|
| 638 |
+
|
| 639 |
+
|
| 640 |
+
def test_broken_meta() -> None:
|
| 641 |
+
"""Test parsing broken meta."""
|
| 642 |
+
with pytest.raises(ParseError):
|
| 643 |
+
parse("Args:")
|
| 644 |
+
|
| 645 |
+
with pytest.raises(ParseError):
|
| 646 |
+
parse("Args:\n herp derp")
|
| 647 |
+
|
| 648 |
+
|
| 649 |
+
def test_unknown_meta() -> None:
|
| 650 |
+
"""Test parsing unknown meta."""
|
| 651 |
+
docstring = parse(
|
| 652 |
+
"""Short desc
|
| 653 |
+
|
| 654 |
+
Unknown 0:
|
| 655 |
+
title0: content0
|
| 656 |
+
|
| 657 |
+
Args:
|
| 658 |
+
arg0: desc0
|
| 659 |
+
arg1: desc1
|
| 660 |
+
|
| 661 |
+
Unknown1:
|
| 662 |
+
title1: content1
|
| 663 |
+
|
| 664 |
+
Unknown2:
|
| 665 |
+
title2: content2
|
| 666 |
+
"""
|
| 667 |
+
)
|
| 668 |
+
|
| 669 |
+
assert docstring.params[0].arg_name == "arg0"
|
| 670 |
+
assert docstring.params[0].description == "desc0"
|
| 671 |
+
assert docstring.params[1].arg_name == "arg1"
|
| 672 |
+
assert docstring.params[1].description == "desc1"
|
| 673 |
+
|
| 674 |
+
|
| 675 |
+
def test_broken_arguments() -> None:
|
| 676 |
+
"""Test parsing broken arguments."""
|
| 677 |
+
with pytest.raises(ParseError):
|
| 678 |
+
parse(
|
| 679 |
+
"""This is a test
|
| 680 |
+
|
| 681 |
+
Args:
|
| 682 |
+
param - poorly formatted
|
| 683 |
+
"""
|
| 684 |
+
)
|
| 685 |
+
|
| 686 |
+
|
| 687 |
+
def test_empty_example() -> None:
|
| 688 |
+
"""Test parsing empty examples section."""
|
| 689 |
+
docstring = parse(
|
| 690 |
+
"""Short description
|
| 691 |
+
|
| 692 |
+
Example:
|
| 693 |
+
|
| 694 |
+
Raises:
|
| 695 |
+
IOError: some error
|
| 696 |
+
"""
|
| 697 |
+
)
|
| 698 |
+
|
| 699 |
+
assert len(docstring.examples) == 1
|
| 700 |
+
assert docstring.examples[0].args == ["examples"]
|
| 701 |
+
assert docstring.examples[0].description == ""
|
| 702 |
+
|
| 703 |
+
|
| 704 |
+
@pytest.mark.parametrize(
|
| 705 |
+
"source, expected",
|
| 706 |
+
[
|
| 707 |
+
("", ""),
|
| 708 |
+
("\n", ""),
|
| 709 |
+
("Short description", "Short description"),
|
| 710 |
+
("\nShort description\n", "Short description"),
|
| 711 |
+
("\n Short description\n", "Short description"),
|
| 712 |
+
(
|
| 713 |
+
"Short description\n\nLong description",
|
| 714 |
+
"Short description\n\nLong description",
|
| 715 |
+
),
|
| 716 |
+
(
|
| 717 |
+
"""
|
| 718 |
+
Short description
|
| 719 |
+
|
| 720 |
+
Long description
|
| 721 |
+
""",
|
| 722 |
+
"Short description\n\nLong description",
|
| 723 |
+
),
|
| 724 |
+
(
|
| 725 |
+
"""
|
| 726 |
+
Short description
|
| 727 |
+
|
| 728 |
+
Long description
|
| 729 |
+
Second line
|
| 730 |
+
""",
|
| 731 |
+
"Short description\n\nLong description\nSecond line",
|
| 732 |
+
),
|
| 733 |
+
(
|
| 734 |
+
"Short description\nLong description",
|
| 735 |
+
"Short description\nLong description",
|
| 736 |
+
),
|
| 737 |
+
(
|
| 738 |
+
"""
|
| 739 |
+
Short description
|
| 740 |
+
Long description
|
| 741 |
+
""",
|
| 742 |
+
"Short description\nLong description",
|
| 743 |
+
),
|
| 744 |
+
(
|
| 745 |
+
"\nShort description\nLong description\n",
|
| 746 |
+
"Short description\nLong description",
|
| 747 |
+
),
|
| 748 |
+
(
|
| 749 |
+
"""
|
| 750 |
+
Short description
|
| 751 |
+
Long description
|
| 752 |
+
Second line
|
| 753 |
+
""",
|
| 754 |
+
"Short description\nLong description\nSecond line",
|
| 755 |
+
),
|
| 756 |
+
(
|
| 757 |
+
"""
|
| 758 |
+
Short description
|
| 759 |
+
Meta:
|
| 760 |
+
asd
|
| 761 |
+
""",
|
| 762 |
+
"Short description\nMeta:\n asd",
|
| 763 |
+
),
|
| 764 |
+
(
|
| 765 |
+
"""
|
| 766 |
+
Short description
|
| 767 |
+
Long description
|
| 768 |
+
Meta:
|
| 769 |
+
asd
|
| 770 |
+
""",
|
| 771 |
+
"Short description\nLong description\nMeta:\n asd",
|
| 772 |
+
),
|
| 773 |
+
(
|
| 774 |
+
"""
|
| 775 |
+
Short description
|
| 776 |
+
First line
|
| 777 |
+
Second line
|
| 778 |
+
Meta:
|
| 779 |
+
asd
|
| 780 |
+
""",
|
| 781 |
+
"Short description\n"
|
| 782 |
+
"First line\n"
|
| 783 |
+
" Second line\n"
|
| 784 |
+
"Meta:\n"
|
| 785 |
+
" asd",
|
| 786 |
+
),
|
| 787 |
+
(
|
| 788 |
+
"""
|
| 789 |
+
Short description
|
| 790 |
+
|
| 791 |
+
First line
|
| 792 |
+
Second line
|
| 793 |
+
Meta:
|
| 794 |
+
asd
|
| 795 |
+
""",
|
| 796 |
+
"Short description\n"
|
| 797 |
+
"\n"
|
| 798 |
+
"First line\n"
|
| 799 |
+
" Second line\n"
|
| 800 |
+
"Meta:\n"
|
| 801 |
+
" asd",
|
| 802 |
+
),
|
| 803 |
+
(
|
| 804 |
+
"""
|
| 805 |
+
Short description
|
| 806 |
+
|
| 807 |
+
First line
|
| 808 |
+
Second line
|
| 809 |
+
|
| 810 |
+
Meta:
|
| 811 |
+
asd
|
| 812 |
+
""",
|
| 813 |
+
"Short description\n"
|
| 814 |
+
"\n"
|
| 815 |
+
"First line\n"
|
| 816 |
+
" Second line\n"
|
| 817 |
+
"\n"
|
| 818 |
+
"Meta:\n"
|
| 819 |
+
" asd",
|
| 820 |
+
),
|
| 821 |
+
(
|
| 822 |
+
"""
|
| 823 |
+
Short description
|
| 824 |
+
|
| 825 |
+
Meta:
|
| 826 |
+
asd
|
| 827 |
+
1
|
| 828 |
+
2
|
| 829 |
+
3
|
| 830 |
+
""",
|
| 831 |
+
"Short description\n"
|
| 832 |
+
"\n"
|
| 833 |
+
"Meta:\n"
|
| 834 |
+
" asd\n"
|
| 835 |
+
" 1\n"
|
| 836 |
+
" 2\n"
|
| 837 |
+
" 3",
|
| 838 |
+
),
|
| 839 |
+
(
|
| 840 |
+
"""
|
| 841 |
+
Short description
|
| 842 |
+
|
| 843 |
+
Meta1:
|
| 844 |
+
asd
|
| 845 |
+
1
|
| 846 |
+
2
|
| 847 |
+
3
|
| 848 |
+
Meta2:
|
| 849 |
+
herp
|
| 850 |
+
Meta3:
|
| 851 |
+
derp
|
| 852 |
+
""",
|
| 853 |
+
"Short description\n"
|
| 854 |
+
"\n"
|
| 855 |
+
"Meta1:\n"
|
| 856 |
+
" asd\n"
|
| 857 |
+
" 1\n"
|
| 858 |
+
" 2\n"
|
| 859 |
+
" 3\n"
|
| 860 |
+
"Meta2:\n"
|
| 861 |
+
" herp\n"
|
| 862 |
+
"Meta3:\n"
|
| 863 |
+
" derp",
|
| 864 |
+
),
|
| 865 |
+
(
|
| 866 |
+
"""
|
| 867 |
+
Short description
|
| 868 |
+
|
| 869 |
+
Args:
|
| 870 |
+
name: description 1
|
| 871 |
+
priority (int): description 2
|
| 872 |
+
sender (str, optional): description 3
|
| 873 |
+
message (str, optional): description 4, defaults to 'hello'
|
| 874 |
+
multiline (str?):
|
| 875 |
+
long description 5,
|
| 876 |
+
defaults to 'bye'
|
| 877 |
+
""",
|
| 878 |
+
"Short description\n"
|
| 879 |
+
"\n"
|
| 880 |
+
"Args:\n"
|
| 881 |
+
" name: description 1\n"
|
| 882 |
+
" priority (int): description 2\n"
|
| 883 |
+
" sender (str?): description 3\n"
|
| 884 |
+
" message (str?): description 4, defaults to 'hello'\n"
|
| 885 |
+
" multiline (str?): long description 5,\n"
|
| 886 |
+
" defaults to 'bye'",
|
| 887 |
+
),
|
| 888 |
+
(
|
| 889 |
+
"""
|
| 890 |
+
Short description
|
| 891 |
+
Raises:
|
| 892 |
+
ValueError: description
|
| 893 |
+
""",
|
| 894 |
+
"Short description\nRaises:\n ValueError: description",
|
| 895 |
+
),
|
| 896 |
+
],
|
| 897 |
+
)
|
| 898 |
+
def test_compose(source: str, expected: str) -> None:
|
| 899 |
+
"""Test compose in default mode."""
|
| 900 |
+
assert compose(parse(source)) == expected
|
| 901 |
+
|
| 902 |
+
|
| 903 |
+
@pytest.mark.parametrize(
|
| 904 |
+
"source, expected",
|
| 905 |
+
[
|
| 906 |
+
(
|
| 907 |
+
"""
|
| 908 |
+
Short description
|
| 909 |
+
|
| 910 |
+
Args:
|
| 911 |
+
name: description 1
|
| 912 |
+
priority (int): description 2
|
| 913 |
+
sender (str, optional): description 3
|
| 914 |
+
message (str, optional): description 4, defaults to 'hello'
|
| 915 |
+
multiline (str?):
|
| 916 |
+
long description 5,
|
| 917 |
+
defaults to 'bye'
|
| 918 |
+
""",
|
| 919 |
+
"Short description\n"
|
| 920 |
+
"\n"
|
| 921 |
+
"Args:\n"
|
| 922 |
+
" name: description 1\n"
|
| 923 |
+
" priority (int): description 2\n"
|
| 924 |
+
" sender (str, optional): description 3\n"
|
| 925 |
+
" message (str, optional): description 4, defaults to 'hello'\n"
|
| 926 |
+
" multiline (str, optional): long description 5,\n"
|
| 927 |
+
" defaults to 'bye'",
|
| 928 |
+
),
|
| 929 |
+
],
|
| 930 |
+
)
|
| 931 |
+
def test_compose_clean(source: str, expected: str) -> None:
|
| 932 |
+
"""Test compose in clean mode."""
|
| 933 |
+
assert (
|
| 934 |
+
compose(parse(source), rendering_style=RenderingStyle.CLEAN)
|
| 935 |
+
== expected
|
| 936 |
+
)
|
| 937 |
+
|
| 938 |
+
|
| 939 |
+
@pytest.mark.parametrize(
|
| 940 |
+
"source, expected",
|
| 941 |
+
[
|
| 942 |
+
(
|
| 943 |
+
"""
|
| 944 |
+
Short description
|
| 945 |
+
|
| 946 |
+
Args:
|
| 947 |
+
name: description 1
|
| 948 |
+
priority (int): description 2
|
| 949 |
+
sender (str, optional): description 3
|
| 950 |
+
message (str, optional): description 4, defaults to 'hello'
|
| 951 |
+
multiline (str?):
|
| 952 |
+
long description 5,
|
| 953 |
+
defaults to 'bye'
|
| 954 |
+
""",
|
| 955 |
+
"Short description\n"
|
| 956 |
+
"\n"
|
| 957 |
+
"Args:\n"
|
| 958 |
+
" name:\n"
|
| 959 |
+
" description 1\n"
|
| 960 |
+
" priority (int):\n"
|
| 961 |
+
" description 2\n"
|
| 962 |
+
" sender (str, optional):\n"
|
| 963 |
+
" description 3\n"
|
| 964 |
+
" message (str, optional):\n"
|
| 965 |
+
" description 4, defaults to 'hello'\n"
|
| 966 |
+
" multiline (str, optional):\n"
|
| 967 |
+
" long description 5,\n"
|
| 968 |
+
" defaults to 'bye'",
|
| 969 |
+
),
|
| 970 |
+
],
|
| 971 |
+
)
|
| 972 |
+
def test_compose_expanded(source: str, expected: str) -> None:
|
| 973 |
+
"""Test compose in expanded mode."""
|
| 974 |
+
assert (
|
| 975 |
+
compose(parse(source), rendering_style=RenderingStyle.EXPANDED)
|
| 976 |
+
== expected
|
| 977 |
+
)
|
parrot/lib/python3.10/site-packages/docstring_parser/tests/test_numpydoc.py
ADDED
|
@@ -0,0 +1,1087 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
| 1 |
+
"""Tests for numpydoc-style docstring routines."""
|
| 2 |
+
import typing as T
|
| 3 |
+
|
| 4 |
+
import pytest
|
| 5 |
+
from docstring_parser.numpydoc import compose, parse
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
@pytest.mark.parametrize(
|
| 9 |
+
"source, expected",
|
| 10 |
+
[
|
| 11 |
+
("", None),
|
| 12 |
+
("\n", None),
|
| 13 |
+
("Short description", "Short description"),
|
| 14 |
+
("\nShort description\n", "Short description"),
|
| 15 |
+
("\n Short description\n", "Short description"),
|
| 16 |
+
],
|
| 17 |
+
)
|
| 18 |
+
def test_short_description(source: str, expected: str) -> None:
|
| 19 |
+
"""Test parsing short description."""
|
| 20 |
+
docstring = parse(source)
|
| 21 |
+
assert docstring.short_description == expected
|
| 22 |
+
assert docstring.long_description is None
|
| 23 |
+
assert not docstring.meta
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
@pytest.mark.parametrize(
|
| 27 |
+
"source, expected_short_desc, expected_long_desc, expected_blank",
|
| 28 |
+
[
|
| 29 |
+
(
|
| 30 |
+
"Short description\n\nLong description",
|
| 31 |
+
"Short description",
|
| 32 |
+
"Long description",
|
| 33 |
+
True,
|
| 34 |
+
),
|
| 35 |
+
(
|
| 36 |
+
"""
|
| 37 |
+
Short description
|
| 38 |
+
|
| 39 |
+
Long description
|
| 40 |
+
""",
|
| 41 |
+
"Short description",
|
| 42 |
+
"Long description",
|
| 43 |
+
True,
|
| 44 |
+
),
|
| 45 |
+
(
|
| 46 |
+
"""
|
| 47 |
+
Short description
|
| 48 |
+
|
| 49 |
+
Long description
|
| 50 |
+
Second line
|
| 51 |
+
""",
|
| 52 |
+
"Short description",
|
| 53 |
+
"Long description\nSecond line",
|
| 54 |
+
True,
|
| 55 |
+
),
|
| 56 |
+
(
|
| 57 |
+
"Short description\nLong description",
|
| 58 |
+
"Short description",
|
| 59 |
+
"Long description",
|
| 60 |
+
False,
|
| 61 |
+
),
|
| 62 |
+
(
|
| 63 |
+
"""
|
| 64 |
+
Short description
|
| 65 |
+
Long description
|
| 66 |
+
""",
|
| 67 |
+
"Short description",
|
| 68 |
+
"Long description",
|
| 69 |
+
False,
|
| 70 |
+
),
|
| 71 |
+
(
|
| 72 |
+
"\nShort description\nLong description\n",
|
| 73 |
+
"Short description",
|
| 74 |
+
"Long description",
|
| 75 |
+
False,
|
| 76 |
+
),
|
| 77 |
+
(
|
| 78 |
+
"""
|
| 79 |
+
Short description
|
| 80 |
+
Long description
|
| 81 |
+
Second line
|
| 82 |
+
""",
|
| 83 |
+
"Short description",
|
| 84 |
+
"Long description\nSecond line",
|
| 85 |
+
False,
|
| 86 |
+
),
|
| 87 |
+
],
|
| 88 |
+
)
|
| 89 |
+
def test_long_description(
|
| 90 |
+
source: str,
|
| 91 |
+
expected_short_desc: str,
|
| 92 |
+
expected_long_desc: str,
|
| 93 |
+
expected_blank: bool,
|
| 94 |
+
) -> None:
|
| 95 |
+
"""Test parsing long description."""
|
| 96 |
+
docstring = parse(source)
|
| 97 |
+
assert docstring.short_description == expected_short_desc
|
| 98 |
+
assert docstring.long_description == expected_long_desc
|
| 99 |
+
assert docstring.blank_after_short_description == expected_blank
|
| 100 |
+
assert not docstring.meta
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
@pytest.mark.parametrize(
|
| 104 |
+
"source, expected_short_desc, expected_long_desc, "
|
| 105 |
+
"expected_blank_short_desc, expected_blank_long_desc",
|
| 106 |
+
[
|
| 107 |
+
(
|
| 108 |
+
"""
|
| 109 |
+
Short description
|
| 110 |
+
Parameters
|
| 111 |
+
----------
|
| 112 |
+
asd
|
| 113 |
+
""",
|
| 114 |
+
"Short description",
|
| 115 |
+
None,
|
| 116 |
+
False,
|
| 117 |
+
False,
|
| 118 |
+
),
|
| 119 |
+
(
|
| 120 |
+
"""
|
| 121 |
+
Short description
|
| 122 |
+
Long description
|
| 123 |
+
Parameters
|
| 124 |
+
----------
|
| 125 |
+
asd
|
| 126 |
+
""",
|
| 127 |
+
"Short description",
|
| 128 |
+
"Long description",
|
| 129 |
+
False,
|
| 130 |
+
False,
|
| 131 |
+
),
|
| 132 |
+
(
|
| 133 |
+
"""
|
| 134 |
+
Short description
|
| 135 |
+
First line
|
| 136 |
+
Second line
|
| 137 |
+
Parameters
|
| 138 |
+
----------
|
| 139 |
+
asd
|
| 140 |
+
""",
|
| 141 |
+
"Short description",
|
| 142 |
+
"First line\n Second line",
|
| 143 |
+
False,
|
| 144 |
+
False,
|
| 145 |
+
),
|
| 146 |
+
(
|
| 147 |
+
"""
|
| 148 |
+
Short description
|
| 149 |
+
|
| 150 |
+
First line
|
| 151 |
+
Second line
|
| 152 |
+
Parameters
|
| 153 |
+
----------
|
| 154 |
+
asd
|
| 155 |
+
""",
|
| 156 |
+
"Short description",
|
| 157 |
+
"First line\n Second line",
|
| 158 |
+
True,
|
| 159 |
+
False,
|
| 160 |
+
),
|
| 161 |
+
(
|
| 162 |
+
"""
|
| 163 |
+
Short description
|
| 164 |
+
|
| 165 |
+
First line
|
| 166 |
+
Second line
|
| 167 |
+
|
| 168 |
+
Parameters
|
| 169 |
+
----------
|
| 170 |
+
asd
|
| 171 |
+
""",
|
| 172 |
+
"Short description",
|
| 173 |
+
"First line\n Second line",
|
| 174 |
+
True,
|
| 175 |
+
True,
|
| 176 |
+
),
|
| 177 |
+
(
|
| 178 |
+
"""
|
| 179 |
+
Parameters
|
| 180 |
+
----------
|
| 181 |
+
asd
|
| 182 |
+
""",
|
| 183 |
+
None,
|
| 184 |
+
None,
|
| 185 |
+
False,
|
| 186 |
+
False,
|
| 187 |
+
),
|
| 188 |
+
],
|
| 189 |
+
)
|
| 190 |
+
def test_meta_newlines(
|
| 191 |
+
source: str,
|
| 192 |
+
expected_short_desc: T.Optional[str],
|
| 193 |
+
expected_long_desc: T.Optional[str],
|
| 194 |
+
expected_blank_short_desc: bool,
|
| 195 |
+
expected_blank_long_desc: bool,
|
| 196 |
+
) -> None:
|
| 197 |
+
"""Test parsing newlines around description sections."""
|
| 198 |
+
docstring = parse(source)
|
| 199 |
+
assert docstring.short_description == expected_short_desc
|
| 200 |
+
assert docstring.long_description == expected_long_desc
|
| 201 |
+
assert docstring.blank_after_short_description == expected_blank_short_desc
|
| 202 |
+
assert docstring.blank_after_long_description == expected_blank_long_desc
|
| 203 |
+
assert len(docstring.meta) == 1
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
def test_meta_with_multiline_description() -> None:
|
| 207 |
+
"""Test parsing multiline meta documentation."""
|
| 208 |
+
docstring = parse(
|
| 209 |
+
"""
|
| 210 |
+
Short description
|
| 211 |
+
|
| 212 |
+
Parameters
|
| 213 |
+
----------
|
| 214 |
+
spam
|
| 215 |
+
asd
|
| 216 |
+
1
|
| 217 |
+
2
|
| 218 |
+
3
|
| 219 |
+
"""
|
| 220 |
+
)
|
| 221 |
+
assert docstring.short_description == "Short description"
|
| 222 |
+
assert len(docstring.meta) == 1
|
| 223 |
+
assert docstring.meta[0].args == ["param", "spam"]
|
| 224 |
+
assert docstring.meta[0].arg_name == "spam"
|
| 225 |
+
assert docstring.meta[0].description == "asd\n1\n 2\n3"
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
@pytest.mark.parametrize(
|
| 229 |
+
"source, expected_is_optional, expected_type_name, expected_default",
|
| 230 |
+
[
|
| 231 |
+
(
|
| 232 |
+
"""
|
| 233 |
+
Parameters
|
| 234 |
+
----------
|
| 235 |
+
arg1 : int
|
| 236 |
+
The first arg
|
| 237 |
+
""",
|
| 238 |
+
False,
|
| 239 |
+
"int",
|
| 240 |
+
None,
|
| 241 |
+
),
|
| 242 |
+
(
|
| 243 |
+
"""
|
| 244 |
+
Parameters
|
| 245 |
+
----------
|
| 246 |
+
arg2 : str
|
| 247 |
+
The second arg
|
| 248 |
+
""",
|
| 249 |
+
False,
|
| 250 |
+
"str",
|
| 251 |
+
None,
|
| 252 |
+
),
|
| 253 |
+
(
|
| 254 |
+
"""
|
| 255 |
+
Parameters
|
| 256 |
+
----------
|
| 257 |
+
arg3 : float, optional
|
| 258 |
+
The third arg. Default is 1.0.
|
| 259 |
+
""",
|
| 260 |
+
True,
|
| 261 |
+
"float",
|
| 262 |
+
"1.0",
|
| 263 |
+
),
|
| 264 |
+
(
|
| 265 |
+
"""
|
| 266 |
+
Parameters
|
| 267 |
+
----------
|
| 268 |
+
arg4 : Optional[Dict[str, Any]], optional
|
| 269 |
+
The fourth arg. Defaults to None
|
| 270 |
+
""",
|
| 271 |
+
True,
|
| 272 |
+
"Optional[Dict[str, Any]]",
|
| 273 |
+
"None",
|
| 274 |
+
),
|
| 275 |
+
(
|
| 276 |
+
"""
|
| 277 |
+
Parameters
|
| 278 |
+
----------
|
| 279 |
+
arg5 : str, optional
|
| 280 |
+
The fifth arg. Default: DEFAULT_ARGS
|
| 281 |
+
""",
|
| 282 |
+
True,
|
| 283 |
+
"str",
|
| 284 |
+
"DEFAULT_ARGS",
|
| 285 |
+
),
|
| 286 |
+
(
|
| 287 |
+
"""
|
| 288 |
+
Parameters
|
| 289 |
+
----------
|
| 290 |
+
parameter_without_default : int
|
| 291 |
+
The parameter_without_default is required.
|
| 292 |
+
""",
|
| 293 |
+
False,
|
| 294 |
+
"int",
|
| 295 |
+
None,
|
| 296 |
+
),
|
| 297 |
+
],
|
| 298 |
+
)
|
| 299 |
+
def test_default_args(
|
| 300 |
+
source: str,
|
| 301 |
+
expected_is_optional: bool,
|
| 302 |
+
expected_type_name: T.Optional[str],
|
| 303 |
+
expected_default: T.Optional[str],
|
| 304 |
+
) -> None:
|
| 305 |
+
"""Test parsing default arguments."""
|
| 306 |
+
docstring = parse(source)
|
| 307 |
+
assert docstring is not None
|
| 308 |
+
assert len(docstring.params) == 1
|
| 309 |
+
|
| 310 |
+
arg1 = docstring.params[0]
|
| 311 |
+
assert arg1.is_optional == expected_is_optional
|
| 312 |
+
assert arg1.type_name == expected_type_name
|
| 313 |
+
assert arg1.default == expected_default
|
| 314 |
+
|
| 315 |
+
|
| 316 |
+
def test_multiple_meta() -> None:
|
| 317 |
+
"""Test parsing multiple meta."""
|
| 318 |
+
docstring = parse(
|
| 319 |
+
"""
|
| 320 |
+
Short description
|
| 321 |
+
|
| 322 |
+
Parameters
|
| 323 |
+
----------
|
| 324 |
+
spam
|
| 325 |
+
asd
|
| 326 |
+
1
|
| 327 |
+
2
|
| 328 |
+
3
|
| 329 |
+
|
| 330 |
+
Raises
|
| 331 |
+
------
|
| 332 |
+
bla
|
| 333 |
+
herp
|
| 334 |
+
yay
|
| 335 |
+
derp
|
| 336 |
+
"""
|
| 337 |
+
)
|
| 338 |
+
assert docstring.short_description == "Short description"
|
| 339 |
+
assert len(docstring.meta) == 3
|
| 340 |
+
assert docstring.meta[0].args == ["param", "spam"]
|
| 341 |
+
assert docstring.meta[0].arg_name == "spam"
|
| 342 |
+
assert docstring.meta[0].description == "asd\n1\n 2\n3"
|
| 343 |
+
assert docstring.meta[1].args == ["raises", "bla"]
|
| 344 |
+
assert docstring.meta[1].type_name == "bla"
|
| 345 |
+
assert docstring.meta[1].description == "herp"
|
| 346 |
+
assert docstring.meta[2].args == ["raises", "yay"]
|
| 347 |
+
assert docstring.meta[2].type_name == "yay"
|
| 348 |
+
assert docstring.meta[2].description == "derp"
|
| 349 |
+
|
| 350 |
+
|
| 351 |
+
def test_params() -> None:
|
| 352 |
+
"""Test parsing params."""
|
| 353 |
+
docstring = parse("Short description")
|
| 354 |
+
assert len(docstring.params) == 0
|
| 355 |
+
|
| 356 |
+
docstring = parse(
|
| 357 |
+
"""
|
| 358 |
+
Short description
|
| 359 |
+
|
| 360 |
+
Parameters
|
| 361 |
+
----------
|
| 362 |
+
name
|
| 363 |
+
description 1
|
| 364 |
+
priority : int
|
| 365 |
+
description 2
|
| 366 |
+
sender : str, optional
|
| 367 |
+
description 3
|
| 368 |
+
ratio : Optional[float], optional
|
| 369 |
+
description 4
|
| 370 |
+
"""
|
| 371 |
+
)
|
| 372 |
+
assert len(docstring.params) == 4
|
| 373 |
+
assert docstring.params[0].arg_name == "name"
|
| 374 |
+
assert docstring.params[0].type_name is None
|
| 375 |
+
assert docstring.params[0].description == "description 1"
|
| 376 |
+
assert not docstring.params[0].is_optional
|
| 377 |
+
assert docstring.params[1].arg_name == "priority"
|
| 378 |
+
assert docstring.params[1].type_name == "int"
|
| 379 |
+
assert docstring.params[1].description == "description 2"
|
| 380 |
+
assert not docstring.params[1].is_optional
|
| 381 |
+
assert docstring.params[2].arg_name == "sender"
|
| 382 |
+
assert docstring.params[2].type_name == "str"
|
| 383 |
+
assert docstring.params[2].description == "description 3"
|
| 384 |
+
assert docstring.params[2].is_optional
|
| 385 |
+
assert docstring.params[3].arg_name == "ratio"
|
| 386 |
+
assert docstring.params[3].type_name == "Optional[float]"
|
| 387 |
+
assert docstring.params[3].description == "description 4"
|
| 388 |
+
assert docstring.params[3].is_optional
|
| 389 |
+
|
| 390 |
+
docstring = parse(
|
| 391 |
+
"""
|
| 392 |
+
Short description
|
| 393 |
+
|
| 394 |
+
Parameters
|
| 395 |
+
----------
|
| 396 |
+
name
|
| 397 |
+
description 1
|
| 398 |
+
with multi-line text
|
| 399 |
+
priority : int
|
| 400 |
+
description 2
|
| 401 |
+
"""
|
| 402 |
+
)
|
| 403 |
+
assert len(docstring.params) == 2
|
| 404 |
+
assert docstring.params[0].arg_name == "name"
|
| 405 |
+
assert docstring.params[0].type_name is None
|
| 406 |
+
assert docstring.params[0].description == (
|
| 407 |
+
"description 1\nwith multi-line text"
|
| 408 |
+
)
|
| 409 |
+
assert docstring.params[1].arg_name == "priority"
|
| 410 |
+
assert docstring.params[1].type_name == "int"
|
| 411 |
+
assert docstring.params[1].description == "description 2"
|
| 412 |
+
|
| 413 |
+
|
| 414 |
+
def test_attributes() -> None:
|
| 415 |
+
"""Test parsing attributes."""
|
| 416 |
+
docstring = parse("Short description")
|
| 417 |
+
assert len(docstring.params) == 0
|
| 418 |
+
|
| 419 |
+
docstring = parse(
|
| 420 |
+
"""
|
| 421 |
+
Short description
|
| 422 |
+
|
| 423 |
+
Attributes
|
| 424 |
+
----------
|
| 425 |
+
name
|
| 426 |
+
description 1
|
| 427 |
+
priority : int
|
| 428 |
+
description 2
|
| 429 |
+
sender : str, optional
|
| 430 |
+
description 3
|
| 431 |
+
ratio : Optional[float], optional
|
| 432 |
+
description 4
|
| 433 |
+
"""
|
| 434 |
+
)
|
| 435 |
+
assert len(docstring.params) == 4
|
| 436 |
+
assert docstring.params[0].arg_name == "name"
|
| 437 |
+
assert docstring.params[0].type_name is None
|
| 438 |
+
assert docstring.params[0].description == "description 1"
|
| 439 |
+
assert not docstring.params[0].is_optional
|
| 440 |
+
assert docstring.params[1].arg_name == "priority"
|
| 441 |
+
assert docstring.params[1].type_name == "int"
|
| 442 |
+
assert docstring.params[1].description == "description 2"
|
| 443 |
+
assert not docstring.params[1].is_optional
|
| 444 |
+
assert docstring.params[2].arg_name == "sender"
|
| 445 |
+
assert docstring.params[2].type_name == "str"
|
| 446 |
+
assert docstring.params[2].description == "description 3"
|
| 447 |
+
assert docstring.params[2].is_optional
|
| 448 |
+
assert docstring.params[3].arg_name == "ratio"
|
| 449 |
+
assert docstring.params[3].type_name == "Optional[float]"
|
| 450 |
+
assert docstring.params[3].description == "description 4"
|
| 451 |
+
assert docstring.params[3].is_optional
|
| 452 |
+
|
| 453 |
+
docstring = parse(
|
| 454 |
+
"""
|
| 455 |
+
Short description
|
| 456 |
+
|
| 457 |
+
Attributes
|
| 458 |
+
----------
|
| 459 |
+
name
|
| 460 |
+
description 1
|
| 461 |
+
with multi-line text
|
| 462 |
+
priority : int
|
| 463 |
+
description 2
|
| 464 |
+
"""
|
| 465 |
+
)
|
| 466 |
+
assert len(docstring.params) == 2
|
| 467 |
+
assert docstring.params[0].arg_name == "name"
|
| 468 |
+
assert docstring.params[0].type_name is None
|
| 469 |
+
assert docstring.params[0].description == (
|
| 470 |
+
"description 1\nwith multi-line text"
|
| 471 |
+
)
|
| 472 |
+
assert docstring.params[1].arg_name == "priority"
|
| 473 |
+
assert docstring.params[1].type_name == "int"
|
| 474 |
+
assert docstring.params[1].description == "description 2"
|
| 475 |
+
|
| 476 |
+
|
| 477 |
+
def test_other_params() -> None:
|
| 478 |
+
"""Test parsing other parameters."""
|
| 479 |
+
docstring = parse(
|
| 480 |
+
"""
|
| 481 |
+
Short description
|
| 482 |
+
Other Parameters
|
| 483 |
+
----------------
|
| 484 |
+
only_seldom_used_keywords : type, optional
|
| 485 |
+
Explanation
|
| 486 |
+
common_parameters_listed_above : type, optional
|
| 487 |
+
Explanation
|
| 488 |
+
"""
|
| 489 |
+
)
|
| 490 |
+
assert len(docstring.meta) == 2
|
| 491 |
+
assert docstring.meta[0].args == [
|
| 492 |
+
"other_param",
|
| 493 |
+
"only_seldom_used_keywords",
|
| 494 |
+
]
|
| 495 |
+
assert docstring.meta[0].arg_name == "only_seldom_used_keywords"
|
| 496 |
+
assert docstring.meta[0].type_name == "type"
|
| 497 |
+
assert docstring.meta[0].is_optional
|
| 498 |
+
assert docstring.meta[0].description == "Explanation"
|
| 499 |
+
|
| 500 |
+
assert docstring.meta[1].args == [
|
| 501 |
+
"other_param",
|
| 502 |
+
"common_parameters_listed_above",
|
| 503 |
+
]
|
| 504 |
+
|
| 505 |
+
|
| 506 |
+
def test_yields() -> None:
|
| 507 |
+
"""Test parsing yields."""
|
| 508 |
+
docstring = parse(
|
| 509 |
+
"""
|
| 510 |
+
Short description
|
| 511 |
+
Yields
|
| 512 |
+
------
|
| 513 |
+
int
|
| 514 |
+
description
|
| 515 |
+
"""
|
| 516 |
+
)
|
| 517 |
+
assert len(docstring.meta) == 1
|
| 518 |
+
assert docstring.meta[0].args == ["yields"]
|
| 519 |
+
assert docstring.meta[0].type_name == "int"
|
| 520 |
+
assert docstring.meta[0].description == "description"
|
| 521 |
+
assert docstring.meta[0].return_name is None
|
| 522 |
+
assert docstring.meta[0].is_generator
|
| 523 |
+
|
| 524 |
+
|
| 525 |
+
def test_returns() -> None:
|
| 526 |
+
"""Test parsing returns."""
|
| 527 |
+
docstring = parse(
|
| 528 |
+
"""
|
| 529 |
+
Short description
|
| 530 |
+
"""
|
| 531 |
+
)
|
| 532 |
+
assert docstring.returns is None
|
| 533 |
+
assert docstring.many_returns is not None
|
| 534 |
+
assert len(docstring.many_returns) == 0
|
| 535 |
+
|
| 536 |
+
docstring = parse(
|
| 537 |
+
"""
|
| 538 |
+
Short description
|
| 539 |
+
Returns
|
| 540 |
+
-------
|
| 541 |
+
type
|
| 542 |
+
"""
|
| 543 |
+
)
|
| 544 |
+
assert docstring.returns is not None
|
| 545 |
+
assert docstring.returns.type_name == "type"
|
| 546 |
+
assert docstring.returns.description is None
|
| 547 |
+
assert docstring.many_returns is not None
|
| 548 |
+
assert len(docstring.many_returns) == 1
|
| 549 |
+
assert docstring.many_returns[0] == docstring.returns
|
| 550 |
+
|
| 551 |
+
docstring = parse(
|
| 552 |
+
"""
|
| 553 |
+
Short description
|
| 554 |
+
Returns
|
| 555 |
+
-------
|
| 556 |
+
int
|
| 557 |
+
description
|
| 558 |
+
"""
|
| 559 |
+
)
|
| 560 |
+
assert docstring.returns is not None
|
| 561 |
+
assert docstring.returns.type_name == "int"
|
| 562 |
+
assert docstring.returns.description == "description"
|
| 563 |
+
assert docstring.many_returns is not None
|
| 564 |
+
assert len(docstring.many_returns) == 1
|
| 565 |
+
assert docstring.many_returns[0] == docstring.returns
|
| 566 |
+
|
| 567 |
+
docstring = parse(
|
| 568 |
+
"""
|
| 569 |
+
Returns
|
| 570 |
+
-------
|
| 571 |
+
Optional[Mapping[str, List[int]]]
|
| 572 |
+
A description: with a colon
|
| 573 |
+
"""
|
| 574 |
+
)
|
| 575 |
+
assert docstring.returns is not None
|
| 576 |
+
assert docstring.returns.type_name == "Optional[Mapping[str, List[int]]]"
|
| 577 |
+
assert docstring.returns.description == "A description: with a colon"
|
| 578 |
+
assert docstring.many_returns is not None
|
| 579 |
+
assert len(docstring.many_returns) == 1
|
| 580 |
+
assert docstring.many_returns[0] == docstring.returns
|
| 581 |
+
|
| 582 |
+
docstring = parse(
|
| 583 |
+
"""
|
| 584 |
+
Short description
|
| 585 |
+
Returns
|
| 586 |
+
-------
|
| 587 |
+
int
|
| 588 |
+
description
|
| 589 |
+
with much text
|
| 590 |
+
|
| 591 |
+
even some spacing
|
| 592 |
+
"""
|
| 593 |
+
)
|
| 594 |
+
assert docstring.returns is not None
|
| 595 |
+
assert docstring.returns.type_name == "int"
|
| 596 |
+
assert docstring.returns.description == (
|
| 597 |
+
"description\nwith much text\n\neven some spacing"
|
| 598 |
+
)
|
| 599 |
+
assert docstring.many_returns is not None
|
| 600 |
+
assert len(docstring.many_returns) == 1
|
| 601 |
+
assert docstring.many_returns[0] == docstring.returns
|
| 602 |
+
|
| 603 |
+
docstring = parse(
|
| 604 |
+
"""
|
| 605 |
+
Short description
|
| 606 |
+
Returns
|
| 607 |
+
-------
|
| 608 |
+
a : int
|
| 609 |
+
description for a
|
| 610 |
+
b : str
|
| 611 |
+
description for b
|
| 612 |
+
"""
|
| 613 |
+
)
|
| 614 |
+
assert docstring.returns is not None
|
| 615 |
+
assert docstring.returns.type_name == "int"
|
| 616 |
+
assert docstring.returns.description == ("description for a")
|
| 617 |
+
assert docstring.many_returns is not None
|
| 618 |
+
assert len(docstring.many_returns) == 2
|
| 619 |
+
assert docstring.many_returns[0].type_name == "int"
|
| 620 |
+
assert docstring.many_returns[0].description == "description for a"
|
| 621 |
+
assert docstring.many_returns[0].return_name == "a"
|
| 622 |
+
assert docstring.many_returns[1].type_name == "str"
|
| 623 |
+
assert docstring.many_returns[1].description == "description for b"
|
| 624 |
+
assert docstring.many_returns[1].return_name == "b"
|
| 625 |
+
|
| 626 |
+
|
| 627 |
+
def test_raises() -> None:
|
| 628 |
+
"""Test parsing raises."""
|
| 629 |
+
docstring = parse(
|
| 630 |
+
"""
|
| 631 |
+
Short description
|
| 632 |
+
"""
|
| 633 |
+
)
|
| 634 |
+
assert len(docstring.raises) == 0
|
| 635 |
+
|
| 636 |
+
docstring = parse(
|
| 637 |
+
"""
|
| 638 |
+
Short description
|
| 639 |
+
Raises
|
| 640 |
+
------
|
| 641 |
+
ValueError
|
| 642 |
+
description
|
| 643 |
+
"""
|
| 644 |
+
)
|
| 645 |
+
assert len(docstring.raises) == 1
|
| 646 |
+
assert docstring.raises[0].type_name == "ValueError"
|
| 647 |
+
assert docstring.raises[0].description == "description"
|
| 648 |
+
|
| 649 |
+
|
| 650 |
+
def test_warns() -> None:
|
| 651 |
+
"""Test parsing warns."""
|
| 652 |
+
docstring = parse(
|
| 653 |
+
"""
|
| 654 |
+
Short description
|
| 655 |
+
Warns
|
| 656 |
+
-----
|
| 657 |
+
UserWarning
|
| 658 |
+
description
|
| 659 |
+
"""
|
| 660 |
+
)
|
| 661 |
+
assert len(docstring.meta) == 1
|
| 662 |
+
assert docstring.meta[0].type_name == "UserWarning"
|
| 663 |
+
assert docstring.meta[0].description == "description"
|
| 664 |
+
|
| 665 |
+
|
| 666 |
+
def test_simple_sections() -> None:
|
| 667 |
+
"""Test parsing simple sections."""
|
| 668 |
+
docstring = parse(
|
| 669 |
+
"""
|
| 670 |
+
Short description
|
| 671 |
+
|
| 672 |
+
See Also
|
| 673 |
+
--------
|
| 674 |
+
something : some thing you can also see
|
| 675 |
+
actually, anything can go in this section
|
| 676 |
+
|
| 677 |
+
Warnings
|
| 678 |
+
--------
|
| 679 |
+
Here be dragons
|
| 680 |
+
|
| 681 |
+
Notes
|
| 682 |
+
-----
|
| 683 |
+
None of this is real
|
| 684 |
+
|
| 685 |
+
References
|
| 686 |
+
----------
|
| 687 |
+
Cite the relevant literature, e.g. [1]_. You may also cite these
|
| 688 |
+
references in the notes section above.
|
| 689 |
+
|
| 690 |
+
.. [1] O. McNoleg, "The integration of GIS, remote sensing,
|
| 691 |
+
expert systems and adaptive co-kriging for environmental habitat
|
| 692 |
+
modelling of the Highland Haggis using object-oriented, fuzzy-logic
|
| 693 |
+
and neural-network techniques," Computers & Geosciences, vol. 22,
|
| 694 |
+
pp. 585-588, 1996.
|
| 695 |
+
"""
|
| 696 |
+
)
|
| 697 |
+
assert len(docstring.meta) == 4
|
| 698 |
+
assert docstring.meta[0].args == ["see_also"]
|
| 699 |
+
assert docstring.meta[0].description == (
|
| 700 |
+
"something : some thing you can also see\n"
|
| 701 |
+
"actually, anything can go in this section"
|
| 702 |
+
)
|
| 703 |
+
|
| 704 |
+
assert docstring.meta[1].args == ["warnings"]
|
| 705 |
+
assert docstring.meta[1].description == "Here be dragons"
|
| 706 |
+
|
| 707 |
+
assert docstring.meta[2].args == ["notes"]
|
| 708 |
+
assert docstring.meta[2].description == "None of this is real"
|
| 709 |
+
|
| 710 |
+
assert docstring.meta[3].args == ["references"]
|
| 711 |
+
|
| 712 |
+
|
| 713 |
+
@pytest.mark.parametrize(
|
| 714 |
+
"source, expected_results",
|
| 715 |
+
[
|
| 716 |
+
(
|
| 717 |
+
"Description\nExamples\n--------\nlong example\n\nmore here",
|
| 718 |
+
[
|
| 719 |
+
(None, "long example\n\nmore here"),
|
| 720 |
+
],
|
| 721 |
+
),
|
| 722 |
+
(
|
| 723 |
+
"Description\nExamples\n--------\n>>> test",
|
| 724 |
+
[
|
| 725 |
+
(">>> test", ""),
|
| 726 |
+
],
|
| 727 |
+
),
|
| 728 |
+
(
|
| 729 |
+
"Description\nExamples\n--------\n>>> testa\n>>> testb",
|
| 730 |
+
[
|
| 731 |
+
(">>> testa\n>>> testb", ""),
|
| 732 |
+
],
|
| 733 |
+
),
|
| 734 |
+
(
|
| 735 |
+
"Description\nExamples\n--------\n>>> test1\ndesc1",
|
| 736 |
+
[
|
| 737 |
+
(">>> test1", "desc1"),
|
| 738 |
+
],
|
| 739 |
+
),
|
| 740 |
+
(
|
| 741 |
+
"Description\nExamples\n--------\n"
|
| 742 |
+
">>> test1a\n>>> test1b\ndesc1a\ndesc1b",
|
| 743 |
+
[
|
| 744 |
+
(">>> test1a\n>>> test1b", "desc1a\ndesc1b"),
|
| 745 |
+
],
|
| 746 |
+
),
|
| 747 |
+
(
|
| 748 |
+
"Description\nExamples\n--------\n"
|
| 749 |
+
">>> test1\ndesc1\n>>> test2\ndesc2",
|
| 750 |
+
[
|
| 751 |
+
(">>> test1", "desc1"),
|
| 752 |
+
(">>> test2", "desc2"),
|
| 753 |
+
],
|
| 754 |
+
),
|
| 755 |
+
(
|
| 756 |
+
"Description\nExamples\n--------\n"
|
| 757 |
+
">>> test1a\n>>> test1b\ndesc1a\ndesc1b\n"
|
| 758 |
+
">>> test2a\n>>> test2b\ndesc2a\ndesc2b\n",
|
| 759 |
+
[
|
| 760 |
+
(">>> test1a\n>>> test1b", "desc1a\ndesc1b"),
|
| 761 |
+
(">>> test2a\n>>> test2b", "desc2a\ndesc2b"),
|
| 762 |
+
],
|
| 763 |
+
),
|
| 764 |
+
(
|
| 765 |
+
"Description\nExamples\n--------\n"
|
| 766 |
+
" >>> test1a\n >>> test1b\n desc1a\n desc1b\n"
|
| 767 |
+
" >>> test2a\n >>> test2b\n desc2a\n desc2b\n",
|
| 768 |
+
[
|
| 769 |
+
(">>> test1a\n>>> test1b", "desc1a\ndesc1b"),
|
| 770 |
+
(">>> test2a\n>>> test2b", "desc2a\ndesc2b"),
|
| 771 |
+
],
|
| 772 |
+
),
|
| 773 |
+
],
|
| 774 |
+
)
|
| 775 |
+
def test_examples(
|
| 776 |
+
source, expected_results: T.List[T.Tuple[T.Optional[str], str]]
|
| 777 |
+
) -> None:
|
| 778 |
+
"""Test parsing examples."""
|
| 779 |
+
docstring = parse(source)
|
| 780 |
+
assert len(docstring.meta) == len(expected_results)
|
| 781 |
+
for meta, expected_result in zip(docstring.meta, expected_results):
|
| 782 |
+
assert meta.description == expected_result[1]
|
| 783 |
+
assert len(docstring.examples) == len(expected_results)
|
| 784 |
+
for example, expected_result in zip(docstring.examples, expected_results):
|
| 785 |
+
assert example.snippet == expected_result[0]
|
| 786 |
+
assert example.description == expected_result[1]
|
| 787 |
+
|
| 788 |
+
|
| 789 |
+
@pytest.mark.parametrize(
|
| 790 |
+
"source, expected_depr_version, expected_depr_desc",
|
| 791 |
+
[
|
| 792 |
+
(
|
| 793 |
+
"Short description\n\n.. deprecated:: 1.6.0\n This is busted!",
|
| 794 |
+
"1.6.0",
|
| 795 |
+
"This is busted!",
|
| 796 |
+
),
|
| 797 |
+
(
|
| 798 |
+
(
|
| 799 |
+
"Short description\n\n"
|
| 800 |
+
".. deprecated:: 1.6.0\n"
|
| 801 |
+
" This description has\n"
|
| 802 |
+
" multiple lines!"
|
| 803 |
+
),
|
| 804 |
+
"1.6.0",
|
| 805 |
+
"This description has\nmultiple lines!",
|
| 806 |
+
),
|
| 807 |
+
("Short description\n\n.. deprecated:: 1.6.0", "1.6.0", None),
|
| 808 |
+
(
|
| 809 |
+
"Short description\n\n.. deprecated::\n No version!",
|
| 810 |
+
None,
|
| 811 |
+
"No version!",
|
| 812 |
+
),
|
| 813 |
+
],
|
| 814 |
+
)
|
| 815 |
+
def test_deprecation(
|
| 816 |
+
source: str,
|
| 817 |
+
expected_depr_version: T.Optional[str],
|
| 818 |
+
expected_depr_desc: T.Optional[str],
|
| 819 |
+
) -> None:
|
| 820 |
+
"""Test parsing deprecation notes."""
|
| 821 |
+
docstring = parse(source)
|
| 822 |
+
|
| 823 |
+
assert docstring.deprecation is not None
|
| 824 |
+
assert docstring.deprecation.version == expected_depr_version
|
| 825 |
+
assert docstring.deprecation.description == expected_depr_desc
|
| 826 |
+
|
| 827 |
+
|
| 828 |
+
@pytest.mark.parametrize(
|
| 829 |
+
"source, expected",
|
| 830 |
+
[
|
| 831 |
+
("", ""),
|
| 832 |
+
("\n", ""),
|
| 833 |
+
("Short description", "Short description"),
|
| 834 |
+
("\nShort description\n", "Short description"),
|
| 835 |
+
("\n Short description\n", "Short description"),
|
| 836 |
+
(
|
| 837 |
+
"Short description\n\nLong description",
|
| 838 |
+
"Short description\n\nLong description",
|
| 839 |
+
),
|
| 840 |
+
(
|
| 841 |
+
"""
|
| 842 |
+
Short description
|
| 843 |
+
|
| 844 |
+
Long description
|
| 845 |
+
""",
|
| 846 |
+
"Short description\n\nLong description",
|
| 847 |
+
),
|
| 848 |
+
(
|
| 849 |
+
"""
|
| 850 |
+
Short description
|
| 851 |
+
|
| 852 |
+
Long description
|
| 853 |
+
Second line
|
| 854 |
+
""",
|
| 855 |
+
"Short description\n\nLong description\nSecond line",
|
| 856 |
+
),
|
| 857 |
+
(
|
| 858 |
+
"Short description\nLong description",
|
| 859 |
+
"Short description\nLong description",
|
| 860 |
+
),
|
| 861 |
+
(
|
| 862 |
+
"""
|
| 863 |
+
Short description
|
| 864 |
+
Long description
|
| 865 |
+
""",
|
| 866 |
+
"Short description\nLong description",
|
| 867 |
+
),
|
| 868 |
+
(
|
| 869 |
+
"\nShort description\nLong description\n",
|
| 870 |
+
"Short description\nLong description",
|
| 871 |
+
),
|
| 872 |
+
(
|
| 873 |
+
"""
|
| 874 |
+
Short description
|
| 875 |
+
Long description
|
| 876 |
+
Second line
|
| 877 |
+
""",
|
| 878 |
+
"Short description\nLong description\nSecond line",
|
| 879 |
+
),
|
| 880 |
+
(
|
| 881 |
+
"""
|
| 882 |
+
Short description
|
| 883 |
+
Meta:
|
| 884 |
+
-----
|
| 885 |
+
asd
|
| 886 |
+
""",
|
| 887 |
+
"Short description\nMeta:\n-----\n asd",
|
| 888 |
+
),
|
| 889 |
+
(
|
| 890 |
+
"""
|
| 891 |
+
Short description
|
| 892 |
+
Long description
|
| 893 |
+
Meta:
|
| 894 |
+
-----
|
| 895 |
+
asd
|
| 896 |
+
""",
|
| 897 |
+
"Short description\n"
|
| 898 |
+
"Long description\n"
|
| 899 |
+
"Meta:\n"
|
| 900 |
+
"-----\n"
|
| 901 |
+
" asd",
|
| 902 |
+
),
|
| 903 |
+
(
|
| 904 |
+
"""
|
| 905 |
+
Short description
|
| 906 |
+
First line
|
| 907 |
+
Second line
|
| 908 |
+
Meta:
|
| 909 |
+
-----
|
| 910 |
+
asd
|
| 911 |
+
""",
|
| 912 |
+
"Short description\n"
|
| 913 |
+
"First line\n"
|
| 914 |
+
" Second line\n"
|
| 915 |
+
"Meta:\n"
|
| 916 |
+
"-----\n"
|
| 917 |
+
" asd",
|
| 918 |
+
),
|
| 919 |
+
(
|
| 920 |
+
"""
|
| 921 |
+
Short description
|
| 922 |
+
|
| 923 |
+
First line
|
| 924 |
+
Second line
|
| 925 |
+
Meta:
|
| 926 |
+
-----
|
| 927 |
+
asd
|
| 928 |
+
""",
|
| 929 |
+
"Short description\n"
|
| 930 |
+
"\n"
|
| 931 |
+
"First line\n"
|
| 932 |
+
" Second line\n"
|
| 933 |
+
"Meta:\n"
|
| 934 |
+
"-----\n"
|
| 935 |
+
" asd",
|
| 936 |
+
),
|
| 937 |
+
(
|
| 938 |
+
"""
|
| 939 |
+
Short description
|
| 940 |
+
|
| 941 |
+
First line
|
| 942 |
+
Second line
|
| 943 |
+
|
| 944 |
+
Meta:
|
| 945 |
+
-----
|
| 946 |
+
asd
|
| 947 |
+
""",
|
| 948 |
+
"Short description\n"
|
| 949 |
+
"\n"
|
| 950 |
+
"First line\n"
|
| 951 |
+
" Second line\n"
|
| 952 |
+
"\n"
|
| 953 |
+
"Meta:\n"
|
| 954 |
+
"-----\n"
|
| 955 |
+
" asd",
|
| 956 |
+
),
|
| 957 |
+
(
|
| 958 |
+
"""
|
| 959 |
+
Short description
|
| 960 |
+
|
| 961 |
+
Meta:
|
| 962 |
+
-----
|
| 963 |
+
asd
|
| 964 |
+
1
|
| 965 |
+
2
|
| 966 |
+
3
|
| 967 |
+
""",
|
| 968 |
+
"Short description\n"
|
| 969 |
+
"\n"
|
| 970 |
+
"Meta:\n"
|
| 971 |
+
"-----\n"
|
| 972 |
+
" asd\n"
|
| 973 |
+
" 1\n"
|
| 974 |
+
" 2\n"
|
| 975 |
+
" 3",
|
| 976 |
+
),
|
| 977 |
+
(
|
| 978 |
+
"""
|
| 979 |
+
Short description
|
| 980 |
+
|
| 981 |
+
Meta1:
|
| 982 |
+
------
|
| 983 |
+
asd
|
| 984 |
+
1
|
| 985 |
+
2
|
| 986 |
+
3
|
| 987 |
+
Meta2:
|
| 988 |
+
------
|
| 989 |
+
herp
|
| 990 |
+
Meta3:
|
| 991 |
+
------
|
| 992 |
+
derp
|
| 993 |
+
""",
|
| 994 |
+
"Short description\n"
|
| 995 |
+
"\n"
|
| 996 |
+
"Meta1:\n"
|
| 997 |
+
"------\n"
|
| 998 |
+
" asd\n"
|
| 999 |
+
" 1\n"
|
| 1000 |
+
" 2\n"
|
| 1001 |
+
" 3\n"
|
| 1002 |
+
"Meta2:\n"
|
| 1003 |
+
"------\n"
|
| 1004 |
+
" herp\n"
|
| 1005 |
+
"Meta3:\n"
|
| 1006 |
+
"------\n"
|
| 1007 |
+
" derp",
|
| 1008 |
+
),
|
| 1009 |
+
(
|
| 1010 |
+
"""
|
| 1011 |
+
Short description
|
| 1012 |
+
|
| 1013 |
+
Parameters:
|
| 1014 |
+
-----------
|
| 1015 |
+
name
|
| 1016 |
+
description 1
|
| 1017 |
+
priority: int
|
| 1018 |
+
description 2
|
| 1019 |
+
sender: str, optional
|
| 1020 |
+
description 3
|
| 1021 |
+
message: str, optional
|
| 1022 |
+
description 4, defaults to 'hello'
|
| 1023 |
+
multiline: str, optional
|
| 1024 |
+
long description 5,
|
| 1025 |
+
defaults to 'bye'
|
| 1026 |
+
""",
|
| 1027 |
+
"Short description\n"
|
| 1028 |
+
"\n"
|
| 1029 |
+
"Parameters:\n"
|
| 1030 |
+
"-----------\n"
|
| 1031 |
+
" name\n"
|
| 1032 |
+
" description 1\n"
|
| 1033 |
+
" priority: int\n"
|
| 1034 |
+
" description 2\n"
|
| 1035 |
+
" sender: str, optional\n"
|
| 1036 |
+
" description 3\n"
|
| 1037 |
+
" message: str, optional\n"
|
| 1038 |
+
" description 4, defaults to 'hello'\n"
|
| 1039 |
+
" multiline: str, optional\n"
|
| 1040 |
+
" long description 5,\n"
|
| 1041 |
+
" defaults to 'bye'",
|
| 1042 |
+
),
|
| 1043 |
+
(
|
| 1044 |
+
"""
|
| 1045 |
+
Short description
|
| 1046 |
+
Raises:
|
| 1047 |
+
-------
|
| 1048 |
+
ValueError
|
| 1049 |
+
description
|
| 1050 |
+
""",
|
| 1051 |
+
"Short description\n"
|
| 1052 |
+
"Raises:\n"
|
| 1053 |
+
"-------\n"
|
| 1054 |
+
" ValueError\n"
|
| 1055 |
+
" description",
|
| 1056 |
+
),
|
| 1057 |
+
(
|
| 1058 |
+
"""
|
| 1059 |
+
Description
|
| 1060 |
+
Examples:
|
| 1061 |
+
--------
|
| 1062 |
+
>>> test1a
|
| 1063 |
+
>>> test1b
|
| 1064 |
+
desc1a
|
| 1065 |
+
desc1b
|
| 1066 |
+
>>> test2a
|
| 1067 |
+
>>> test2b
|
| 1068 |
+
desc2a
|
| 1069 |
+
desc2b
|
| 1070 |
+
""",
|
| 1071 |
+
"Description\n"
|
| 1072 |
+
"Examples:\n"
|
| 1073 |
+
"--------\n"
|
| 1074 |
+
">>> test1a\n"
|
| 1075 |
+
">>> test1b\n"
|
| 1076 |
+
"desc1a\n"
|
| 1077 |
+
"desc1b\n"
|
| 1078 |
+
">>> test2a\n"
|
| 1079 |
+
">>> test2b\n"
|
| 1080 |
+
"desc2a\n"
|
| 1081 |
+
"desc2b",
|
| 1082 |
+
),
|
| 1083 |
+
],
|
| 1084 |
+
)
|
| 1085 |
+
def test_compose(source: str, expected: str) -> None:
|
| 1086 |
+
"""Test compose in default mode."""
|
| 1087 |
+
assert compose(parse(source)) == expected
|
parrot/lib/python3.10/site-packages/docstring_parser/tests/test_parse_from_object.py
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for parse_from_object function and attribute docstrings."""
|
| 2 |
+
from unittest.mock import patch
|
| 3 |
+
|
| 4 |
+
from docstring_parser import parse_from_object
|
| 5 |
+
|
| 6 |
+
module_attr: int = 1
|
| 7 |
+
"""Description for module_attr"""
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def test_from_module_attribute_docstrings() -> None:
|
| 11 |
+
"""Test the parse of attribute docstrings from a module."""
|
| 12 |
+
from . import test_parse_from_object # pylint: disable=C0415,W0406
|
| 13 |
+
|
| 14 |
+
docstring = parse_from_object(test_parse_from_object)
|
| 15 |
+
|
| 16 |
+
assert "parse_from_object" in docstring.short_description
|
| 17 |
+
assert len(docstring.params) == 1
|
| 18 |
+
assert docstring.params[0].arg_name == "module_attr"
|
| 19 |
+
assert docstring.params[0].type_name == "int"
|
| 20 |
+
assert docstring.params[0].description == "Description for module_attr"
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def test_from_class_attribute_docstrings() -> None:
|
| 24 |
+
"""Test the parse of attribute docstrings from a class."""
|
| 25 |
+
|
| 26 |
+
class StandardCase:
|
| 27 |
+
"""Short description
|
| 28 |
+
Long description
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
attr_one: str
|
| 32 |
+
"""Description for attr_one"""
|
| 33 |
+
attr_two: bool = False
|
| 34 |
+
"""Description for attr_two"""
|
| 35 |
+
|
| 36 |
+
docstring = parse_from_object(StandardCase)
|
| 37 |
+
|
| 38 |
+
assert docstring.short_description == "Short description"
|
| 39 |
+
assert docstring.long_description == "Long description"
|
| 40 |
+
assert docstring.description == "Short description\nLong description"
|
| 41 |
+
assert len(docstring.params) == 2
|
| 42 |
+
assert docstring.params[0].arg_name == "attr_one"
|
| 43 |
+
assert docstring.params[0].type_name == "str"
|
| 44 |
+
assert docstring.params[0].description == "Description for attr_one"
|
| 45 |
+
assert docstring.params[1].arg_name == "attr_two"
|
| 46 |
+
assert docstring.params[1].type_name == "bool"
|
| 47 |
+
assert docstring.params[1].description == "Description for attr_two"
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def test_from_class_attribute_docstrings_without_type() -> None:
|
| 51 |
+
"""Test the parse of untyped attribute docstrings."""
|
| 52 |
+
|
| 53 |
+
class WithoutType: # pylint: disable=missing-class-docstring
|
| 54 |
+
attr_one = "value"
|
| 55 |
+
"""Description for attr_one"""
|
| 56 |
+
|
| 57 |
+
docstring = parse_from_object(WithoutType)
|
| 58 |
+
|
| 59 |
+
assert docstring.short_description is None
|
| 60 |
+
assert docstring.long_description is None
|
| 61 |
+
assert docstring.description is None
|
| 62 |
+
assert len(docstring.params) == 1
|
| 63 |
+
assert docstring.params[0].arg_name == "attr_one"
|
| 64 |
+
assert docstring.params[0].type_name is None
|
| 65 |
+
assert docstring.params[0].description == "Description for attr_one"
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def test_from_class_without_source() -> None:
|
| 69 |
+
"""Test the parse of class when source is unavailable."""
|
| 70 |
+
|
| 71 |
+
class WithoutSource:
|
| 72 |
+
"""Short description"""
|
| 73 |
+
|
| 74 |
+
attr_one: str
|
| 75 |
+
"""Description for attr_one"""
|
| 76 |
+
|
| 77 |
+
with patch(
|
| 78 |
+
"inspect.getsource", side_effect=OSError("could not get source code")
|
| 79 |
+
):
|
| 80 |
+
docstring = parse_from_object(WithoutSource)
|
| 81 |
+
|
| 82 |
+
assert docstring.short_description == "Short description"
|
| 83 |
+
assert docstring.long_description is None
|
| 84 |
+
assert docstring.description == "Short description"
|
| 85 |
+
assert len(docstring.params) == 0
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def test_from_function() -> None:
|
| 89 |
+
"""Test the parse of a function docstring."""
|
| 90 |
+
|
| 91 |
+
def a_function(param1: str, param2: int = 2):
|
| 92 |
+
"""Short description
|
| 93 |
+
Args:
|
| 94 |
+
param1: Description for param1
|
| 95 |
+
param2: Description for param2
|
| 96 |
+
"""
|
| 97 |
+
return f"{param1} {param2}"
|
| 98 |
+
|
| 99 |
+
docstring = parse_from_object(a_function)
|
| 100 |
+
|
| 101 |
+
assert docstring.short_description == "Short description"
|
| 102 |
+
assert docstring.description == "Short description"
|
| 103 |
+
assert len(docstring.params) == 2
|
| 104 |
+
assert docstring.params[0].arg_name == "param1"
|
| 105 |
+
assert docstring.params[0].type_name is None
|
| 106 |
+
assert docstring.params[0].description == "Description for param1"
|
| 107 |
+
assert docstring.params[1].arg_name == "param2"
|
| 108 |
+
assert docstring.params[1].type_name is None
|
| 109 |
+
assert docstring.params[1].description == "Description for param2"
|
parrot/lib/python3.10/site-packages/docstring_parser/tests/test_parser.py
ADDED
|
@@ -0,0 +1,222 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for generic docstring routines."""
|
| 2 |
+
import pytest
|
| 3 |
+
from docstring_parser.common import DocstringStyle, ParseError
|
| 4 |
+
from docstring_parser.parser import parse
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def test_rest() -> None:
|
| 8 |
+
"""Test ReST-style parser autodetection."""
|
| 9 |
+
docstring = parse(
|
| 10 |
+
"""
|
| 11 |
+
Short description
|
| 12 |
+
|
| 13 |
+
Long description
|
| 14 |
+
|
| 15 |
+
Causing people to indent:
|
| 16 |
+
|
| 17 |
+
A lot sometimes
|
| 18 |
+
|
| 19 |
+
:param spam: spam desc
|
| 20 |
+
:param int bla: bla desc
|
| 21 |
+
:param str yay:
|
| 22 |
+
:raises ValueError: exc desc
|
| 23 |
+
:returns tuple: ret desc
|
| 24 |
+
"""
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
assert docstring.style == DocstringStyle.REST
|
| 28 |
+
assert docstring.short_description == "Short description"
|
| 29 |
+
assert docstring.long_description == (
|
| 30 |
+
"Long description\n\n"
|
| 31 |
+
"Causing people to indent:\n\n"
|
| 32 |
+
" A lot sometimes"
|
| 33 |
+
)
|
| 34 |
+
assert docstring.description == (
|
| 35 |
+
"Short description\n\n"
|
| 36 |
+
"Long description\n\n"
|
| 37 |
+
"Causing people to indent:\n\n"
|
| 38 |
+
" A lot sometimes"
|
| 39 |
+
)
|
| 40 |
+
assert len(docstring.params) == 3
|
| 41 |
+
assert docstring.params[0].arg_name == "spam"
|
| 42 |
+
assert docstring.params[0].type_name is None
|
| 43 |
+
assert docstring.params[0].description == "spam desc"
|
| 44 |
+
assert docstring.params[1].arg_name == "bla"
|
| 45 |
+
assert docstring.params[1].type_name == "int"
|
| 46 |
+
assert docstring.params[1].description == "bla desc"
|
| 47 |
+
assert docstring.params[2].arg_name == "yay"
|
| 48 |
+
assert docstring.params[2].type_name == "str"
|
| 49 |
+
assert docstring.params[2].description == ""
|
| 50 |
+
assert len(docstring.raises) == 1
|
| 51 |
+
assert docstring.raises[0].type_name == "ValueError"
|
| 52 |
+
assert docstring.raises[0].description == "exc desc"
|
| 53 |
+
assert docstring.returns is not None
|
| 54 |
+
assert docstring.returns.type_name == "tuple"
|
| 55 |
+
assert docstring.returns.description == "ret desc"
|
| 56 |
+
assert docstring.many_returns is not None
|
| 57 |
+
assert len(docstring.many_returns) == 1
|
| 58 |
+
assert docstring.many_returns[0] == docstring.returns
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def test_google() -> None:
|
| 62 |
+
"""Test Google-style parser autodetection."""
|
| 63 |
+
docstring = parse(
|
| 64 |
+
"""Short description
|
| 65 |
+
|
| 66 |
+
Long description
|
| 67 |
+
|
| 68 |
+
Causing people to indent:
|
| 69 |
+
|
| 70 |
+
A lot sometimes
|
| 71 |
+
|
| 72 |
+
Args:
|
| 73 |
+
spam: spam desc
|
| 74 |
+
bla (int): bla desc
|
| 75 |
+
yay (str):
|
| 76 |
+
|
| 77 |
+
Raises:
|
| 78 |
+
ValueError: exc desc
|
| 79 |
+
|
| 80 |
+
Returns:
|
| 81 |
+
tuple: ret desc
|
| 82 |
+
"""
|
| 83 |
+
)
|
| 84 |
+
|
| 85 |
+
assert docstring.style == DocstringStyle.GOOGLE
|
| 86 |
+
assert docstring.short_description == "Short description"
|
| 87 |
+
assert docstring.long_description == (
|
| 88 |
+
"Long description\n\n"
|
| 89 |
+
"Causing people to indent:\n\n"
|
| 90 |
+
" A lot sometimes"
|
| 91 |
+
)
|
| 92 |
+
assert docstring.description == (
|
| 93 |
+
"Short description\n\n"
|
| 94 |
+
"Long description\n\n"
|
| 95 |
+
"Causing people to indent:\n\n"
|
| 96 |
+
" A lot sometimes"
|
| 97 |
+
)
|
| 98 |
+
assert len(docstring.params) == 3
|
| 99 |
+
assert docstring.params[0].arg_name == "spam"
|
| 100 |
+
assert docstring.params[0].type_name is None
|
| 101 |
+
assert docstring.params[0].description == "spam desc"
|
| 102 |
+
assert docstring.params[1].arg_name == "bla"
|
| 103 |
+
assert docstring.params[1].type_name == "int"
|
| 104 |
+
assert docstring.params[1].description == "bla desc"
|
| 105 |
+
assert docstring.params[2].arg_name == "yay"
|
| 106 |
+
assert docstring.params[2].type_name == "str"
|
| 107 |
+
assert docstring.params[2].description == ""
|
| 108 |
+
assert len(docstring.raises) == 1
|
| 109 |
+
assert docstring.raises[0].type_name == "ValueError"
|
| 110 |
+
assert docstring.raises[0].description == "exc desc"
|
| 111 |
+
assert docstring.returns is not None
|
| 112 |
+
assert docstring.returns.type_name == "tuple"
|
| 113 |
+
assert docstring.returns.description == "ret desc"
|
| 114 |
+
assert docstring.many_returns is not None
|
| 115 |
+
assert len(docstring.many_returns) == 1
|
| 116 |
+
assert docstring.many_returns[0] == docstring.returns
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
def test_numpydoc() -> None:
|
| 120 |
+
"""Test numpydoc-style parser autodetection."""
|
| 121 |
+
docstring = parse(
|
| 122 |
+
"""Short description
|
| 123 |
+
|
| 124 |
+
Long description
|
| 125 |
+
|
| 126 |
+
Causing people to indent:
|
| 127 |
+
|
| 128 |
+
A lot sometimes
|
| 129 |
+
|
| 130 |
+
Parameters
|
| 131 |
+
----------
|
| 132 |
+
spam
|
| 133 |
+
spam desc
|
| 134 |
+
bla : int
|
| 135 |
+
bla desc
|
| 136 |
+
yay : str
|
| 137 |
+
|
| 138 |
+
Raises
|
| 139 |
+
------
|
| 140 |
+
ValueError
|
| 141 |
+
exc desc
|
| 142 |
+
|
| 143 |
+
Other Parameters
|
| 144 |
+
----------------
|
| 145 |
+
this_guy : int, optional
|
| 146 |
+
you know him
|
| 147 |
+
|
| 148 |
+
Returns
|
| 149 |
+
-------
|
| 150 |
+
tuple
|
| 151 |
+
ret desc
|
| 152 |
+
|
| 153 |
+
See Also
|
| 154 |
+
--------
|
| 155 |
+
multiple lines...
|
| 156 |
+
something else?
|
| 157 |
+
|
| 158 |
+
Warnings
|
| 159 |
+
--------
|
| 160 |
+
multiple lines...
|
| 161 |
+
none of this is real!
|
| 162 |
+
"""
|
| 163 |
+
)
|
| 164 |
+
|
| 165 |
+
assert docstring.style == DocstringStyle.NUMPYDOC
|
| 166 |
+
assert docstring.short_description == "Short description"
|
| 167 |
+
assert docstring.long_description == (
|
| 168 |
+
"Long description\n\n"
|
| 169 |
+
"Causing people to indent:\n\n"
|
| 170 |
+
" A lot sometimes"
|
| 171 |
+
)
|
| 172 |
+
assert docstring.description == (
|
| 173 |
+
"Short description\n\n"
|
| 174 |
+
"Long description\n\n"
|
| 175 |
+
"Causing people to indent:\n\n"
|
| 176 |
+
" A lot sometimes"
|
| 177 |
+
)
|
| 178 |
+
assert len(docstring.params) == 4
|
| 179 |
+
assert docstring.params[0].arg_name == "spam"
|
| 180 |
+
assert docstring.params[0].type_name is None
|
| 181 |
+
assert docstring.params[0].description == "spam desc"
|
| 182 |
+
assert docstring.params[1].arg_name == "bla"
|
| 183 |
+
assert docstring.params[1].type_name == "int"
|
| 184 |
+
assert docstring.params[1].description == "bla desc"
|
| 185 |
+
assert docstring.params[2].arg_name == "yay"
|
| 186 |
+
assert docstring.params[2].type_name == "str"
|
| 187 |
+
assert docstring.params[2].description is None
|
| 188 |
+
assert docstring.params[3].arg_name == "this_guy"
|
| 189 |
+
assert docstring.params[3].type_name == "int"
|
| 190 |
+
assert docstring.params[3].is_optional
|
| 191 |
+
assert docstring.params[3].description == "you know him"
|
| 192 |
+
|
| 193 |
+
assert len(docstring.raises) == 1
|
| 194 |
+
assert docstring.raises[0].type_name == "ValueError"
|
| 195 |
+
assert docstring.raises[0].description == "exc desc"
|
| 196 |
+
assert docstring.returns is not None
|
| 197 |
+
assert docstring.returns.type_name == "tuple"
|
| 198 |
+
assert docstring.returns.description == "ret desc"
|
| 199 |
+
assert docstring.many_returns is not None
|
| 200 |
+
assert len(docstring.many_returns) == 1
|
| 201 |
+
assert docstring.many_returns[0] == docstring.returns
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
def test_autodetection_error_detection() -> None:
|
| 205 |
+
"""Test autodection for the case where one of the parsers throws an error
|
| 206 |
+
and another one succeeds.
|
| 207 |
+
"""
|
| 208 |
+
source = """
|
| 209 |
+
Does something useless
|
| 210 |
+
|
| 211 |
+
:param 3 + 3 a: a param
|
| 212 |
+
"""
|
| 213 |
+
|
| 214 |
+
with pytest.raises(ParseError):
|
| 215 |
+
# assert that one of the parsers does raise
|
| 216 |
+
parse(source, DocstringStyle.REST)
|
| 217 |
+
|
| 218 |
+
# assert that autodetection still works
|
| 219 |
+
docstring = parse(source)
|
| 220 |
+
|
| 221 |
+
assert docstring
|
| 222 |
+
assert docstring.style == DocstringStyle.GOOGLE
|
parrot/lib/python3.10/site-packages/docstring_parser/tests/test_rest.py
ADDED
|
@@ -0,0 +1,541 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Tests for ReST-style docstring routines."""
|
| 2 |
+
import typing as T
|
| 3 |
+
|
| 4 |
+
import pytest
|
| 5 |
+
from docstring_parser.common import ParseError, RenderingStyle
|
| 6 |
+
from docstring_parser.rest import compose, parse
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
@pytest.mark.parametrize(
|
| 10 |
+
"source, expected",
|
| 11 |
+
[
|
| 12 |
+
("", None),
|
| 13 |
+
("\n", None),
|
| 14 |
+
("Short description", "Short description"),
|
| 15 |
+
("\nShort description\n", "Short description"),
|
| 16 |
+
("\n Short description\n", "Short description"),
|
| 17 |
+
],
|
| 18 |
+
)
|
| 19 |
+
def test_short_description(source: str, expected: str) -> None:
|
| 20 |
+
"""Test parsing short description."""
|
| 21 |
+
docstring = parse(source)
|
| 22 |
+
assert docstring.short_description == expected
|
| 23 |
+
assert docstring.description == expected
|
| 24 |
+
assert docstring.long_description is None
|
| 25 |
+
assert not docstring.meta
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
@pytest.mark.parametrize(
|
| 29 |
+
"source, expected_short_desc, expected_long_desc, expected_blank",
|
| 30 |
+
[
|
| 31 |
+
(
|
| 32 |
+
"Short description\n\nLong description",
|
| 33 |
+
"Short description",
|
| 34 |
+
"Long description",
|
| 35 |
+
True,
|
| 36 |
+
),
|
| 37 |
+
(
|
| 38 |
+
"""
|
| 39 |
+
Short description
|
| 40 |
+
|
| 41 |
+
Long description
|
| 42 |
+
""",
|
| 43 |
+
"Short description",
|
| 44 |
+
"Long description",
|
| 45 |
+
True,
|
| 46 |
+
),
|
| 47 |
+
(
|
| 48 |
+
"""
|
| 49 |
+
Short description
|
| 50 |
+
|
| 51 |
+
Long description
|
| 52 |
+
Second line
|
| 53 |
+
""",
|
| 54 |
+
"Short description",
|
| 55 |
+
"Long description\nSecond line",
|
| 56 |
+
True,
|
| 57 |
+
),
|
| 58 |
+
(
|
| 59 |
+
"Short description\nLong description",
|
| 60 |
+
"Short description",
|
| 61 |
+
"Long description",
|
| 62 |
+
False,
|
| 63 |
+
),
|
| 64 |
+
(
|
| 65 |
+
"""
|
| 66 |
+
Short description
|
| 67 |
+
Long description
|
| 68 |
+
""",
|
| 69 |
+
"Short description",
|
| 70 |
+
"Long description",
|
| 71 |
+
False,
|
| 72 |
+
),
|
| 73 |
+
(
|
| 74 |
+
"\nShort description\nLong description\n",
|
| 75 |
+
"Short description",
|
| 76 |
+
"Long description",
|
| 77 |
+
False,
|
| 78 |
+
),
|
| 79 |
+
(
|
| 80 |
+
"""
|
| 81 |
+
Short description
|
| 82 |
+
Long description
|
| 83 |
+
Second line
|
| 84 |
+
""",
|
| 85 |
+
"Short description",
|
| 86 |
+
"Long description\nSecond line",
|
| 87 |
+
False,
|
| 88 |
+
),
|
| 89 |
+
],
|
| 90 |
+
)
|
| 91 |
+
def test_long_description(
|
| 92 |
+
source: str,
|
| 93 |
+
expected_short_desc: str,
|
| 94 |
+
expected_long_desc: str,
|
| 95 |
+
expected_blank: bool,
|
| 96 |
+
) -> None:
|
| 97 |
+
"""Test parsing long description."""
|
| 98 |
+
docstring = parse(source)
|
| 99 |
+
assert docstring.short_description == expected_short_desc
|
| 100 |
+
assert docstring.long_description == expected_long_desc
|
| 101 |
+
assert docstring.blank_after_short_description == expected_blank
|
| 102 |
+
assert not docstring.meta
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
@pytest.mark.parametrize(
|
| 106 |
+
"source, expected_short_desc, expected_long_desc, "
|
| 107 |
+
"expected_blank_short_desc, expected_blank_long_desc, "
|
| 108 |
+
"expected_full_desc",
|
| 109 |
+
[
|
| 110 |
+
(
|
| 111 |
+
"""
|
| 112 |
+
Short description
|
| 113 |
+
:meta: asd
|
| 114 |
+
""",
|
| 115 |
+
"Short description",
|
| 116 |
+
None,
|
| 117 |
+
False,
|
| 118 |
+
False,
|
| 119 |
+
"Short description",
|
| 120 |
+
),
|
| 121 |
+
(
|
| 122 |
+
"""
|
| 123 |
+
Short description
|
| 124 |
+
Long description
|
| 125 |
+
:meta: asd
|
| 126 |
+
""",
|
| 127 |
+
"Short description",
|
| 128 |
+
"Long description",
|
| 129 |
+
False,
|
| 130 |
+
False,
|
| 131 |
+
"Short description\nLong description",
|
| 132 |
+
),
|
| 133 |
+
(
|
| 134 |
+
"""
|
| 135 |
+
Short description
|
| 136 |
+
First line
|
| 137 |
+
Second line
|
| 138 |
+
:meta: asd
|
| 139 |
+
""",
|
| 140 |
+
"Short description",
|
| 141 |
+
"First line\n Second line",
|
| 142 |
+
False,
|
| 143 |
+
False,
|
| 144 |
+
"Short description\nFirst line\n Second line",
|
| 145 |
+
),
|
| 146 |
+
(
|
| 147 |
+
"""
|
| 148 |
+
Short description
|
| 149 |
+
|
| 150 |
+
First line
|
| 151 |
+
Second line
|
| 152 |
+
:meta: asd
|
| 153 |
+
""",
|
| 154 |
+
"Short description",
|
| 155 |
+
"First line\n Second line",
|
| 156 |
+
True,
|
| 157 |
+
False,
|
| 158 |
+
"Short description\n\nFirst line\n Second line",
|
| 159 |
+
),
|
| 160 |
+
(
|
| 161 |
+
"""
|
| 162 |
+
Short description
|
| 163 |
+
|
| 164 |
+
First line
|
| 165 |
+
Second line
|
| 166 |
+
|
| 167 |
+
:meta: asd
|
| 168 |
+
""",
|
| 169 |
+
"Short description",
|
| 170 |
+
"First line\n Second line",
|
| 171 |
+
True,
|
| 172 |
+
True,
|
| 173 |
+
"Short description\n\nFirst line\n Second line",
|
| 174 |
+
),
|
| 175 |
+
(
|
| 176 |
+
"""
|
| 177 |
+
:meta: asd
|
| 178 |
+
""",
|
| 179 |
+
None,
|
| 180 |
+
None,
|
| 181 |
+
False,
|
| 182 |
+
False,
|
| 183 |
+
None,
|
| 184 |
+
),
|
| 185 |
+
],
|
| 186 |
+
)
|
| 187 |
+
def test_meta_newlines(
|
| 188 |
+
source: str,
|
| 189 |
+
expected_short_desc: T.Optional[str],
|
| 190 |
+
expected_long_desc: T.Optional[str],
|
| 191 |
+
expected_blank_short_desc: bool,
|
| 192 |
+
expected_blank_long_desc: bool,
|
| 193 |
+
expected_full_desc: T.Optional[str],
|
| 194 |
+
) -> None:
|
| 195 |
+
"""Test parsing newlines around description sections."""
|
| 196 |
+
docstring = parse(source)
|
| 197 |
+
assert docstring.short_description == expected_short_desc
|
| 198 |
+
assert docstring.long_description == expected_long_desc
|
| 199 |
+
assert docstring.blank_after_short_description == expected_blank_short_desc
|
| 200 |
+
assert docstring.blank_after_long_description == expected_blank_long_desc
|
| 201 |
+
assert docstring.description == expected_full_desc
|
| 202 |
+
assert len(docstring.meta) == 1
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
def test_meta_with_multiline_description() -> None:
|
| 206 |
+
"""Test parsing multiline meta documentation."""
|
| 207 |
+
docstring = parse(
|
| 208 |
+
"""
|
| 209 |
+
Short description
|
| 210 |
+
|
| 211 |
+
:meta: asd
|
| 212 |
+
1
|
| 213 |
+
2
|
| 214 |
+
3
|
| 215 |
+
"""
|
| 216 |
+
)
|
| 217 |
+
assert docstring.short_description == "Short description"
|
| 218 |
+
assert len(docstring.meta) == 1
|
| 219 |
+
assert docstring.meta[0].args == ["meta"]
|
| 220 |
+
assert docstring.meta[0].description == "asd\n1\n 2\n3"
|
| 221 |
+
|
| 222 |
+
|
| 223 |
+
def test_multiple_meta() -> None:
|
| 224 |
+
"""Test parsing multiple meta."""
|
| 225 |
+
docstring = parse(
|
| 226 |
+
"""
|
| 227 |
+
Short description
|
| 228 |
+
|
| 229 |
+
:meta1: asd
|
| 230 |
+
1
|
| 231 |
+
2
|
| 232 |
+
3
|
| 233 |
+
:meta2: herp
|
| 234 |
+
:meta3: derp
|
| 235 |
+
"""
|
| 236 |
+
)
|
| 237 |
+
assert docstring.short_description == "Short description"
|
| 238 |
+
assert len(docstring.meta) == 3
|
| 239 |
+
assert docstring.meta[0].args == ["meta1"]
|
| 240 |
+
assert docstring.meta[0].description == "asd\n1\n 2\n3"
|
| 241 |
+
assert docstring.meta[1].args == ["meta2"]
|
| 242 |
+
assert docstring.meta[1].description == "herp"
|
| 243 |
+
assert docstring.meta[2].args == ["meta3"]
|
| 244 |
+
assert docstring.meta[2].description == "derp"
|
| 245 |
+
|
| 246 |
+
|
| 247 |
+
def test_meta_with_args() -> None:
|
| 248 |
+
"""Test parsing meta with additional arguments."""
|
| 249 |
+
docstring = parse(
|
| 250 |
+
"""
|
| 251 |
+
Short description
|
| 252 |
+
|
| 253 |
+
:meta ene due rabe: asd
|
| 254 |
+
"""
|
| 255 |
+
)
|
| 256 |
+
assert docstring.short_description == "Short description"
|
| 257 |
+
assert len(docstring.meta) == 1
|
| 258 |
+
assert docstring.meta[0].args == ["meta", "ene", "due", "rabe"]
|
| 259 |
+
assert docstring.meta[0].description == "asd"
|
| 260 |
+
|
| 261 |
+
|
| 262 |
+
def test_params() -> None:
|
| 263 |
+
"""Test parsing params."""
|
| 264 |
+
docstring = parse("Short description")
|
| 265 |
+
assert len(docstring.params) == 0
|
| 266 |
+
|
| 267 |
+
docstring = parse(
|
| 268 |
+
"""
|
| 269 |
+
Short description
|
| 270 |
+
|
| 271 |
+
:param name: description 1
|
| 272 |
+
:param int priority: description 2
|
| 273 |
+
:param str? sender: description 3
|
| 274 |
+
:param str? message: description 4, defaults to 'hello'
|
| 275 |
+
:param str? multiline: long description 5,
|
| 276 |
+
defaults to 'bye'
|
| 277 |
+
"""
|
| 278 |
+
)
|
| 279 |
+
assert len(docstring.params) == 5
|
| 280 |
+
assert docstring.params[0].arg_name == "name"
|
| 281 |
+
assert docstring.params[0].type_name is None
|
| 282 |
+
assert docstring.params[0].description == "description 1"
|
| 283 |
+
assert docstring.params[0].default is None
|
| 284 |
+
assert not docstring.params[0].is_optional
|
| 285 |
+
assert docstring.params[1].arg_name == "priority"
|
| 286 |
+
assert docstring.params[1].type_name == "int"
|
| 287 |
+
assert docstring.params[1].description == "description 2"
|
| 288 |
+
assert not docstring.params[1].is_optional
|
| 289 |
+
assert docstring.params[1].default is None
|
| 290 |
+
assert docstring.params[2].arg_name == "sender"
|
| 291 |
+
assert docstring.params[2].type_name == "str"
|
| 292 |
+
assert docstring.params[2].description == "description 3"
|
| 293 |
+
assert docstring.params[2].is_optional
|
| 294 |
+
assert docstring.params[2].default is None
|
| 295 |
+
assert docstring.params[3].arg_name == "message"
|
| 296 |
+
assert docstring.params[3].type_name == "str"
|
| 297 |
+
assert (
|
| 298 |
+
docstring.params[3].description == "description 4, defaults to 'hello'"
|
| 299 |
+
)
|
| 300 |
+
assert docstring.params[3].is_optional
|
| 301 |
+
assert docstring.params[3].default == "'hello'"
|
| 302 |
+
assert docstring.params[4].arg_name == "multiline"
|
| 303 |
+
assert docstring.params[4].type_name == "str"
|
| 304 |
+
assert (
|
| 305 |
+
docstring.params[4].description
|
| 306 |
+
== "long description 5,\ndefaults to 'bye'"
|
| 307 |
+
)
|
| 308 |
+
assert docstring.params[4].is_optional
|
| 309 |
+
assert docstring.params[4].default == "'bye'"
|
| 310 |
+
|
| 311 |
+
docstring = parse(
|
| 312 |
+
"""
|
| 313 |
+
Short description
|
| 314 |
+
|
| 315 |
+
:param a: description a
|
| 316 |
+
:type a: int
|
| 317 |
+
:param int b: description b
|
| 318 |
+
"""
|
| 319 |
+
)
|
| 320 |
+
assert len(docstring.params) == 2
|
| 321 |
+
assert docstring.params[0].arg_name == "a"
|
| 322 |
+
assert docstring.params[0].type_name == "int"
|
| 323 |
+
assert docstring.params[0].description == "description a"
|
| 324 |
+
assert docstring.params[0].default is None
|
| 325 |
+
assert not docstring.params[0].is_optional
|
| 326 |
+
|
| 327 |
+
|
| 328 |
+
def test_returns() -> None:
|
| 329 |
+
"""Test parsing returns."""
|
| 330 |
+
docstring = parse(
|
| 331 |
+
"""
|
| 332 |
+
Short description
|
| 333 |
+
"""
|
| 334 |
+
)
|
| 335 |
+
assert docstring.returns is None
|
| 336 |
+
assert docstring.many_returns is not None
|
| 337 |
+
assert len(docstring.many_returns) == 0
|
| 338 |
+
|
| 339 |
+
docstring = parse(
|
| 340 |
+
"""
|
| 341 |
+
Short description
|
| 342 |
+
:returns: description
|
| 343 |
+
"""
|
| 344 |
+
)
|
| 345 |
+
assert docstring.returns is not None
|
| 346 |
+
assert docstring.returns.type_name is None
|
| 347 |
+
assert docstring.returns.description == "description"
|
| 348 |
+
assert not docstring.returns.is_generator
|
| 349 |
+
assert docstring.many_returns == [docstring.returns]
|
| 350 |
+
|
| 351 |
+
docstring = parse(
|
| 352 |
+
"""
|
| 353 |
+
Short description
|
| 354 |
+
:returns int: description
|
| 355 |
+
"""
|
| 356 |
+
)
|
| 357 |
+
assert docstring.returns is not None
|
| 358 |
+
assert docstring.returns.type_name == "int"
|
| 359 |
+
assert docstring.returns.description == "description"
|
| 360 |
+
assert not docstring.returns.is_generator
|
| 361 |
+
assert docstring.many_returns == [docstring.returns]
|
| 362 |
+
|
| 363 |
+
docstring = parse(
|
| 364 |
+
"""
|
| 365 |
+
Short description
|
| 366 |
+
:returns: description
|
| 367 |
+
:rtype: int
|
| 368 |
+
"""
|
| 369 |
+
)
|
| 370 |
+
assert docstring.returns is not None
|
| 371 |
+
assert docstring.returns.type_name == "int"
|
| 372 |
+
assert docstring.returns.description == "description"
|
| 373 |
+
assert not docstring.returns.is_generator
|
| 374 |
+
assert docstring.many_returns == [docstring.returns]
|
| 375 |
+
|
| 376 |
+
|
| 377 |
+
def test_yields() -> None:
|
| 378 |
+
"""Test parsing yields."""
|
| 379 |
+
docstring = parse(
|
| 380 |
+
"""
|
| 381 |
+
Short description
|
| 382 |
+
"""
|
| 383 |
+
)
|
| 384 |
+
assert docstring.returns is None
|
| 385 |
+
assert docstring.many_returns is not None
|
| 386 |
+
assert len(docstring.many_returns) == 0
|
| 387 |
+
|
| 388 |
+
docstring = parse(
|
| 389 |
+
"""
|
| 390 |
+
Short description
|
| 391 |
+
:yields: description
|
| 392 |
+
"""
|
| 393 |
+
)
|
| 394 |
+
assert docstring.returns is not None
|
| 395 |
+
assert docstring.returns.type_name is None
|
| 396 |
+
assert docstring.returns.description == "description"
|
| 397 |
+
assert docstring.returns.is_generator
|
| 398 |
+
assert docstring.many_returns is not None
|
| 399 |
+
assert len(docstring.many_returns) == 1
|
| 400 |
+
assert docstring.many_returns[0] == docstring.returns
|
| 401 |
+
|
| 402 |
+
docstring = parse(
|
| 403 |
+
"""
|
| 404 |
+
Short description
|
| 405 |
+
:yields int: description
|
| 406 |
+
"""
|
| 407 |
+
)
|
| 408 |
+
assert docstring.returns is not None
|
| 409 |
+
assert docstring.returns.type_name == "int"
|
| 410 |
+
assert docstring.returns.description == "description"
|
| 411 |
+
assert docstring.returns.is_generator
|
| 412 |
+
assert docstring.many_returns is not None
|
| 413 |
+
assert len(docstring.many_returns) == 1
|
| 414 |
+
assert docstring.many_returns[0] == docstring.returns
|
| 415 |
+
|
| 416 |
+
|
| 417 |
+
def test_raises() -> None:
|
| 418 |
+
"""Test parsing raises."""
|
| 419 |
+
docstring = parse(
|
| 420 |
+
"""
|
| 421 |
+
Short description
|
| 422 |
+
"""
|
| 423 |
+
)
|
| 424 |
+
assert len(docstring.raises) == 0
|
| 425 |
+
|
| 426 |
+
docstring = parse(
|
| 427 |
+
"""
|
| 428 |
+
Short description
|
| 429 |
+
:raises: description
|
| 430 |
+
"""
|
| 431 |
+
)
|
| 432 |
+
assert len(docstring.raises) == 1
|
| 433 |
+
assert docstring.raises[0].type_name is None
|
| 434 |
+
assert docstring.raises[0].description == "description"
|
| 435 |
+
|
| 436 |
+
docstring = parse(
|
| 437 |
+
"""
|
| 438 |
+
Short description
|
| 439 |
+
:raises ValueError: description
|
| 440 |
+
"""
|
| 441 |
+
)
|
| 442 |
+
assert len(docstring.raises) == 1
|
| 443 |
+
assert docstring.raises[0].type_name == "ValueError"
|
| 444 |
+
assert docstring.raises[0].description == "description"
|
| 445 |
+
|
| 446 |
+
|
| 447 |
+
def test_broken_meta() -> None:
|
| 448 |
+
"""Test parsing broken meta."""
|
| 449 |
+
with pytest.raises(ParseError):
|
| 450 |
+
parse(":")
|
| 451 |
+
|
| 452 |
+
with pytest.raises(ParseError):
|
| 453 |
+
parse(":param herp derp")
|
| 454 |
+
|
| 455 |
+
with pytest.raises(ParseError):
|
| 456 |
+
parse(":param: invalid")
|
| 457 |
+
|
| 458 |
+
with pytest.raises(ParseError):
|
| 459 |
+
parse(":param with too many args: desc")
|
| 460 |
+
|
| 461 |
+
# these should not raise any errors
|
| 462 |
+
parse(":sthstrange: desc")
|
| 463 |
+
|
| 464 |
+
|
| 465 |
+
def test_deprecation() -> None:
|
| 466 |
+
"""Test parsing deprecation notes."""
|
| 467 |
+
docstring = parse(":deprecation: 1.1.0 this function will be removed")
|
| 468 |
+
assert docstring.deprecation is not None
|
| 469 |
+
assert docstring.deprecation.version == "1.1.0"
|
| 470 |
+
assert docstring.deprecation.description == "this function will be removed"
|
| 471 |
+
|
| 472 |
+
docstring = parse(":deprecation: this function will be removed")
|
| 473 |
+
assert docstring.deprecation is not None
|
| 474 |
+
assert docstring.deprecation.version is None
|
| 475 |
+
assert docstring.deprecation.description == "this function will be removed"
|
| 476 |
+
|
| 477 |
+
|
| 478 |
+
@pytest.mark.parametrize(
|
| 479 |
+
"rendering_style, expected",
|
| 480 |
+
[
|
| 481 |
+
(
|
| 482 |
+
RenderingStyle.COMPACT,
|
| 483 |
+
"Short description.\n"
|
| 484 |
+
"\n"
|
| 485 |
+
"Long description.\n"
|
| 486 |
+
"\n"
|
| 487 |
+
":param int foo: a description\n"
|
| 488 |
+
":param int bar: another description\n"
|
| 489 |
+
":returns float: a return",
|
| 490 |
+
),
|
| 491 |
+
(
|
| 492 |
+
RenderingStyle.CLEAN,
|
| 493 |
+
"Short description.\n"
|
| 494 |
+
"\n"
|
| 495 |
+
"Long description.\n"
|
| 496 |
+
"\n"
|
| 497 |
+
":param int foo: a description\n"
|
| 498 |
+
":param int bar: another description\n"
|
| 499 |
+
":returns float: a return",
|
| 500 |
+
),
|
| 501 |
+
(
|
| 502 |
+
RenderingStyle.EXPANDED,
|
| 503 |
+
"Short description.\n"
|
| 504 |
+
"\n"
|
| 505 |
+
"Long description.\n"
|
| 506 |
+
"\n"
|
| 507 |
+
":param foo:\n"
|
| 508 |
+
" a description\n"
|
| 509 |
+
":type foo: int\n"
|
| 510 |
+
":param bar:\n"
|
| 511 |
+
" another description\n"
|
| 512 |
+
":type bar: int\n"
|
| 513 |
+
":returns:\n"
|
| 514 |
+
" a return\n"
|
| 515 |
+
":rtype: float",
|
| 516 |
+
),
|
| 517 |
+
],
|
| 518 |
+
)
|
| 519 |
+
def test_compose(rendering_style: RenderingStyle, expected: str) -> None:
|
| 520 |
+
"""Test compose"""
|
| 521 |
+
|
| 522 |
+
docstring = parse(
|
| 523 |
+
"""
|
| 524 |
+
Short description.
|
| 525 |
+
|
| 526 |
+
Long description.
|
| 527 |
+
|
| 528 |
+
:param int foo: a description
|
| 529 |
+
:param int bar: another description
|
| 530 |
+
:return float: a return
|
| 531 |
+
"""
|
| 532 |
+
)
|
| 533 |
+
assert compose(docstring, rendering_style=rendering_style) == expected
|
| 534 |
+
|
| 535 |
+
|
| 536 |
+
def test_short_rtype() -> None:
|
| 537 |
+
"""Test abbreviated docstring with only return type information."""
|
| 538 |
+
string = "Short description.\n\n:rtype: float"
|
| 539 |
+
docstring = parse(string)
|
| 540 |
+
rendering_style = RenderingStyle.EXPANDED
|
| 541 |
+
assert compose(docstring, rendering_style=rendering_style) == string
|
parrot/lib/python3.10/site-packages/docstring_parser/tests/test_util.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Test for utility functions."""
|
| 2 |
+
|
| 3 |
+
from docstring_parser.common import DocstringReturns
|
| 4 |
+
from docstring_parser.util import combine_docstrings
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def test_combine_docstrings() -> None:
|
| 8 |
+
"""Test combine_docstrings wrapper."""
|
| 9 |
+
|
| 10 |
+
def fun1(arg_a, arg_b, arg_c, arg_d):
|
| 11 |
+
"""short_description: fun1
|
| 12 |
+
|
| 13 |
+
:param arg_a: fun1
|
| 14 |
+
:param arg_b: fun1
|
| 15 |
+
:return: fun1
|
| 16 |
+
"""
|
| 17 |
+
assert arg_a and arg_b and arg_c and arg_d
|
| 18 |
+
|
| 19 |
+
def fun2(arg_b, arg_c, arg_d, arg_e):
|
| 20 |
+
"""short_description: fun2
|
| 21 |
+
|
| 22 |
+
long_description: fun2
|
| 23 |
+
|
| 24 |
+
:param arg_b: fun2
|
| 25 |
+
:param arg_c: fun2
|
| 26 |
+
:param arg_e: fun2
|
| 27 |
+
"""
|
| 28 |
+
assert arg_b and arg_c and arg_d and arg_e
|
| 29 |
+
|
| 30 |
+
@combine_docstrings(fun1, fun2)
|
| 31 |
+
def decorated1(arg_a, arg_b, arg_c, arg_d, arg_e, arg_f):
|
| 32 |
+
"""
|
| 33 |
+
:param arg_e: decorated
|
| 34 |
+
:param arg_f: decorated
|
| 35 |
+
"""
|
| 36 |
+
assert arg_a and arg_b and arg_c and arg_d and arg_e and arg_f
|
| 37 |
+
|
| 38 |
+
assert decorated1.__doc__ == (
|
| 39 |
+
"short_description: fun2\n"
|
| 40 |
+
"\n"
|
| 41 |
+
"long_description: fun2\n"
|
| 42 |
+
"\n"
|
| 43 |
+
":param arg_a: fun1\n"
|
| 44 |
+
":param arg_b: fun1\n"
|
| 45 |
+
":param arg_c: fun2\n"
|
| 46 |
+
":param arg_e: fun2\n"
|
| 47 |
+
":param arg_f: decorated\n"
|
| 48 |
+
":returns: fun1"
|
| 49 |
+
)
|
| 50 |
+
|
| 51 |
+
@combine_docstrings(fun1, fun2, exclude=[DocstringReturns])
|
| 52 |
+
def decorated2(arg_a, arg_b, arg_c, arg_d, arg_e, arg_f):
|
| 53 |
+
assert arg_a and arg_b and arg_c and arg_d and arg_e and arg_f
|
| 54 |
+
|
| 55 |
+
assert decorated2.__doc__ == (
|
| 56 |
+
"short_description: fun2\n"
|
| 57 |
+
"\n"
|
| 58 |
+
"long_description: fun2\n"
|
| 59 |
+
"\n"
|
| 60 |
+
":param arg_a: fun1\n"
|
| 61 |
+
":param arg_b: fun1\n"
|
| 62 |
+
":param arg_c: fun2\n"
|
| 63 |
+
":param arg_e: fun2"
|
| 64 |
+
)
|
parrot/lib/python3.10/site-packages/docstring_parser/util.py
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Utility functions for working with docstrings."""
|
| 2 |
+
import typing as T
|
| 3 |
+
from collections import ChainMap
|
| 4 |
+
from inspect import Signature
|
| 5 |
+
from itertools import chain
|
| 6 |
+
|
| 7 |
+
from .common import (
|
| 8 |
+
DocstringMeta,
|
| 9 |
+
DocstringParam,
|
| 10 |
+
DocstringReturns,
|
| 11 |
+
DocstringStyle,
|
| 12 |
+
RenderingStyle,
|
| 13 |
+
)
|
| 14 |
+
from .parser import compose, parse
|
| 15 |
+
|
| 16 |
+
_Func = T.Callable[..., T.Any]
|
| 17 |
+
|
| 18 |
+
assert DocstringReturns # used in docstring
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def combine_docstrings(
|
| 22 |
+
*others: _Func,
|
| 23 |
+
exclude: T.Iterable[T.Type[DocstringMeta]] = (),
|
| 24 |
+
style: DocstringStyle = DocstringStyle.AUTO,
|
| 25 |
+
rendering_style: RenderingStyle = RenderingStyle.COMPACT,
|
| 26 |
+
) -> _Func:
|
| 27 |
+
"""A function decorator that parses the docstrings from `others`,
|
| 28 |
+
programmatically combines them with the parsed docstring of the decorated
|
| 29 |
+
function, and replaces the docstring of the decorated function with the
|
| 30 |
+
composed result. Only parameters that are part of the decorated functions
|
| 31 |
+
signature are included in the combined docstring. When multiple sources for
|
| 32 |
+
a parameter or docstring metadata exists then the decorator will first
|
| 33 |
+
default to the wrapped function's value (when available) and otherwise use
|
| 34 |
+
the rightmost definition from ``others``.
|
| 35 |
+
|
| 36 |
+
The following example illustrates its usage:
|
| 37 |
+
|
| 38 |
+
>>> def fun1(a, b, c, d):
|
| 39 |
+
... '''short_description: fun1
|
| 40 |
+
...
|
| 41 |
+
... :param a: fun1
|
| 42 |
+
... :param b: fun1
|
| 43 |
+
... :return: fun1
|
| 44 |
+
... '''
|
| 45 |
+
>>> def fun2(b, c, d, e):
|
| 46 |
+
... '''short_description: fun2
|
| 47 |
+
...
|
| 48 |
+
... long_description: fun2
|
| 49 |
+
...
|
| 50 |
+
... :param b: fun2
|
| 51 |
+
... :param c: fun2
|
| 52 |
+
... :param e: fun2
|
| 53 |
+
... '''
|
| 54 |
+
>>> @combine_docstrings(fun1, fun2)
|
| 55 |
+
>>> def decorated(a, b, c, d, e, f):
|
| 56 |
+
... '''
|
| 57 |
+
... :param e: decorated
|
| 58 |
+
... :param f: decorated
|
| 59 |
+
... '''
|
| 60 |
+
>>> print(decorated.__doc__)
|
| 61 |
+
short_description: fun2
|
| 62 |
+
<BLANKLINE>
|
| 63 |
+
long_description: fun2
|
| 64 |
+
<BLANKLINE>
|
| 65 |
+
:param a: fun1
|
| 66 |
+
:param b: fun1
|
| 67 |
+
:param c: fun2
|
| 68 |
+
:param e: fun2
|
| 69 |
+
:param f: decorated
|
| 70 |
+
:returns: fun1
|
| 71 |
+
>>> @combine_docstrings(fun1, fun2, exclude=[DocstringReturns])
|
| 72 |
+
>>> def decorated(a, b, c, d, e, f): pass
|
| 73 |
+
>>> print(decorated.__doc__)
|
| 74 |
+
short_description: fun2
|
| 75 |
+
<BLANKLINE>
|
| 76 |
+
long_description: fun2
|
| 77 |
+
<BLANKLINE>
|
| 78 |
+
:param a: fun1
|
| 79 |
+
:param b: fun1
|
| 80 |
+
:param c: fun2
|
| 81 |
+
:param e: fun2
|
| 82 |
+
|
| 83 |
+
:param others: callables from which to parse docstrings.
|
| 84 |
+
:param exclude: an iterable of ``DocstringMeta`` subclasses to exclude when
|
| 85 |
+
combining docstrings.
|
| 86 |
+
:param style: style composed docstring. The default will infer the style
|
| 87 |
+
from the decorated function.
|
| 88 |
+
:param rendering_style: The rendering style used to compose a docstring.
|
| 89 |
+
:return: the decorated function with a modified docstring.
|
| 90 |
+
"""
|
| 91 |
+
|
| 92 |
+
def wrapper(func: _Func) -> _Func:
|
| 93 |
+
sig = Signature.from_callable(func)
|
| 94 |
+
|
| 95 |
+
comb_doc = parse(func.__doc__ or "")
|
| 96 |
+
docs = [parse(other.__doc__ or "") for other in others] + [comb_doc]
|
| 97 |
+
params = dict(
|
| 98 |
+
ChainMap(
|
| 99 |
+
*(
|
| 100 |
+
{param.arg_name: param for param in doc.params}
|
| 101 |
+
for doc in docs
|
| 102 |
+
)
|
| 103 |
+
)
|
| 104 |
+
)
|
| 105 |
+
|
| 106 |
+
for doc in reversed(docs):
|
| 107 |
+
if not doc.short_description:
|
| 108 |
+
continue
|
| 109 |
+
comb_doc.short_description = doc.short_description
|
| 110 |
+
comb_doc.blank_after_short_description = (
|
| 111 |
+
doc.blank_after_short_description
|
| 112 |
+
)
|
| 113 |
+
break
|
| 114 |
+
|
| 115 |
+
for doc in reversed(docs):
|
| 116 |
+
if not doc.long_description:
|
| 117 |
+
continue
|
| 118 |
+
comb_doc.long_description = doc.long_description
|
| 119 |
+
comb_doc.blank_after_long_description = (
|
| 120 |
+
doc.blank_after_long_description
|
| 121 |
+
)
|
| 122 |
+
break
|
| 123 |
+
|
| 124 |
+
combined = {}
|
| 125 |
+
for doc in docs:
|
| 126 |
+
metas = {}
|
| 127 |
+
for meta in doc.meta:
|
| 128 |
+
meta_type = type(meta)
|
| 129 |
+
if meta_type in exclude:
|
| 130 |
+
continue
|
| 131 |
+
metas.setdefault(meta_type, []).append(meta)
|
| 132 |
+
for (meta_type, meta) in metas.items():
|
| 133 |
+
combined[meta_type] = meta
|
| 134 |
+
|
| 135 |
+
combined[DocstringParam] = [
|
| 136 |
+
params[name] for name in sig.parameters if name in params
|
| 137 |
+
]
|
| 138 |
+
comb_doc.meta = list(chain(*combined.values()))
|
| 139 |
+
func.__doc__ = compose(
|
| 140 |
+
comb_doc, style=style, rendering_style=rendering_style
|
| 141 |
+
)
|
| 142 |
+
return func
|
| 143 |
+
|
| 144 |
+
return wrapper
|
parrot/lib/python3.10/site-packages/nvidia_cusolver_cu12-11.4.5.107.dist-info/RECORD
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
nvidia/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 2 |
+
nvidia/__pycache__/__init__.cpython-310.pyc,,
|
| 3 |
+
nvidia/cusolver/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 4 |
+
nvidia/cusolver/__pycache__/__init__.cpython-310.pyc,,
|
| 5 |
+
nvidia/cusolver/include/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 6 |
+
nvidia/cusolver/include/__pycache__/__init__.cpython-310.pyc,,
|
| 7 |
+
nvidia/cusolver/include/cusolverDn.h,sha256=8KUcqUxWPr8jpz3ZVpTB6I3IXMme1ok7E7vi9XXKRzk,147406
|
| 8 |
+
nvidia/cusolver/include/cusolverMg.h,sha256=N8989nnS2BleeMyuftbQgBDJ4sMAkLPSnmy_S_7fxng,11549
|
| 9 |
+
nvidia/cusolver/include/cusolverRf.h,sha256=7BZfWeuMJ8w1Pz4iZeGmwvDZbDNNq0ivG5MHtiATtls,14292
|
| 10 |
+
nvidia/cusolver/include/cusolverSp.h,sha256=8fev0XawDBd0xrOxUlQ3WhclKlUuVAT64zKxwnP8iT0,32561
|
| 11 |
+
nvidia/cusolver/include/cusolverSp_LOWLEVEL_PREVIEW.h,sha256=rTuS0rxwGV3bAz50ua59WVPQ9SvlijORj732oPejoCk,37495
|
| 12 |
+
nvidia/cusolver/include/cusolver_common.h,sha256=8SMCLEPkMN9Ni_KANkvPSHCieV1jrTARuS-Mhmuq5H8,8826
|
| 13 |
+
nvidia/cusolver/lib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 14 |
+
nvidia/cusolver/lib/__pycache__/__init__.cpython-310.pyc,,
|
| 15 |
+
nvidia/cusolver/lib/libcusolver.so.11,sha256=ECh6vHzpxfx-fBY3YVZrWZ6uGzYsR-EACRHRmEQ9bVI,114481816
|
| 16 |
+
nvidia/cusolver/lib/libcusolverMg.so.11,sha256=0f3uK8NQhMAFtQ5r76UCApP7coB7wWG2pQOMh1RMmwY,79763496
|
| 17 |
+
nvidia_cusolver_cu12-11.4.5.107.dist-info/INSTALLER,sha256=zuuue4knoyJ-UwPPXg8fezS7VCrXJQrAP7zeNuwvFQg,4
|
| 18 |
+
nvidia_cusolver_cu12-11.4.5.107.dist-info/License.txt,sha256=rW9YU_ugyg0VnQ9Y1JrkmDDC-Mk_epJki5zpCttMbM0,59262
|
| 19 |
+
nvidia_cusolver_cu12-11.4.5.107.dist-info/METADATA,sha256=b8Zxnx3ZVIwttTKBnzgVXjXu8-_pRL6wBkYMTV7i6gA,1626
|
| 20 |
+
nvidia_cusolver_cu12-11.4.5.107.dist-info/RECORD,,
|
| 21 |
+
nvidia_cusolver_cu12-11.4.5.107.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 22 |
+
nvidia_cusolver_cu12-11.4.5.107.dist-info/WHEEL,sha256=-kQi_VMfvRQozZJT7HUPMfY-5vLo0LVTmAylNJ3Ft98,106
|
| 23 |
+
nvidia_cusolver_cu12-11.4.5.107.dist-info/top_level.txt,sha256=fTkAtiFuL16nUrB9ytDDtpytz2t0B4NvYTnRzwAhO14,7
|
parrot/lib/python3.10/site-packages/requests/__pycache__/__version__.cpython-310.pyc
ADDED
|
Binary file (518 Bytes). View file
|
|
|
parrot/lib/python3.10/site-packages/requests/__pycache__/adapters.cpython-310.pyc
ADDED
|
Binary file (22 kB). View file
|
|
|