docsig 0.53.3__tar.gz → 0.54.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: docsig
3
- Version: 0.53.3
3
+ Version: 0.54.0
4
4
  Summary: Check signature params for proper documentation
5
5
  Home-page: https://pypi.org/project/docsig/
6
6
  License: MIT
@@ -222,7 +222,7 @@ It can be added to your .pre-commit-config.yaml as follows:
222
222
 
223
223
  repos:
224
224
  - repo: https://github.com/jshwi/docsig
225
- rev: v0.53.3
225
+ rev: v0.54.0
226
226
  hooks:
227
227
  - id: docsig
228
228
  args:
@@ -194,7 +194,7 @@ It can be added to your .pre-commit-config.yaml as follows:
194
194
 
195
195
  repos:
196
196
  - repo: https://github.com/jshwi/docsig
197
- rev: v0.53.3
197
+ rev: v0.54.0
198
198
  hooks:
199
199
  - id: docsig
200
200
  args:
@@ -12,6 +12,7 @@ import click as _click
12
12
 
13
13
  from ._module import Function as _Function
14
14
  from ._stub import UNNAMED as _UNNAMED
15
+ from ._stub import VALID_DESCRIPTION as _VALID_DESCRIPTION
15
16
  from ._stub import Param as _Param
16
17
  from ._stub import RetType as _RetType
17
18
  from ._utils import almost_equal as _almost_equal
@@ -81,6 +82,7 @@ class Failure(_t.List[str]):
81
82
  for index in range(len(func)):
82
83
  arg = func.signature.args.get(index)
83
84
  doc = func.docstring.args.get(index)
85
+ self._no_description(doc)
84
86
  self._description_syntax(doc)
85
87
  self._indent_syntax(doc)
86
88
 
@@ -153,6 +155,18 @@ class Failure(_t.List[str]):
153
155
 
154
156
  def _missing(self) -> None:
155
157
  if len(self._func.signature.args) > len(self._func.docstring.args):
158
+ # append the parameters that are missing so that they are
159
+ # included in further analysis, that way there are no
160
+ # additional, and redundant, errors
161
+ # this will ensure that both signature and docstring are
162
+ # equal in length, with all parameters that are not
163
+ # documented accounted for
164
+ for count, arg in enumerate(self._func.signature.args, 1):
165
+ if count > len(self._func.docstring.args):
166
+ self._func.docstring.args.append(
167
+ _Param(arg.kind, arg.name, _VALID_DESCRIPTION, 0)
168
+ )
169
+ # params-missing
156
170
  self._add(_E[103])
157
171
 
158
172
  def _duplicates(self) -> None:
@@ -218,6 +232,10 @@ class Failure(_t.List[str]):
218
232
  if doc.indent > 0:
219
233
  self._add(_E[116])
220
234
 
235
+ def _no_description(self, doc: _Param) -> None:
236
+ if doc.description is None:
237
+ self._add(_E[117])
238
+
221
239
  def _invalid_directive(self) -> None:
222
240
  for comment in self._func.comments:
223
241
  if not comment.isvalid:
@@ -17,6 +17,9 @@ import sphinx.ext.napoleon as _s
17
17
  # no function will accidentally have this name
18
18
  UNNAMED = -1000
19
19
 
20
+ # an example of valid parameter description
21
+ VALID_DESCRIPTION = " A valid description."
22
+
20
23
 
21
24
  # noinspection PyTypeChecker
22
25
  class _GoogleDocstring(str):
@@ -134,7 +137,9 @@ class Param(_t.NamedTuple):
134
137
  class _Matches(_t.List[Param]):
135
138
  _pattern = _re.compile(":(.*?):")
136
139
 
137
- def __init__(self, string: str, indent_anomaly: bool) -> None:
140
+ def __init__(
141
+ self, string: str, indent_anomaly: bool, missing_descriptions: bool
142
+ ) -> None:
138
143
  super().__init__()
139
144
  for line in string.splitlines():
140
145
  strip_line = line.lstrip()
@@ -152,7 +157,9 @@ class _Matches(_t.List[Param]):
152
157
  name = UNNAMED
153
158
 
154
159
  if len(match) > 1:
155
- description = match[1]
160
+ second = match[1]
161
+ if second != "" or not missing_descriptions:
162
+ description = second
156
163
 
157
164
  super().append(
158
165
  Param(
@@ -326,6 +333,24 @@ class Docstring(_Stub):
326
333
  # look for spaces in odd intervals
327
334
  return bool(any(i % 2 != 0 for i in leading_spaces))
328
335
 
336
+ @staticmethod
337
+ def _missing_descriptions(string: str) -> bool:
338
+ # find out if parameter is missing a description
339
+ new = ""
340
+ for line in string.strip().splitlines()[2:]:
341
+ line = line.lstrip()
342
+ if not line.startswith(":"):
343
+ # it is not a parameter, it is a next line description
344
+ # append the next entry to the same line
345
+ new = f"{new[:-1]} "
346
+ new += f"{line}\n"
347
+ if not new:
348
+ return True
349
+
350
+ # if it ends with a colon, it's a parameter without a
351
+ # description
352
+ return any(i.endswith(":") for i in new.splitlines())
353
+
329
354
  def __init__(
330
355
  self,
331
356
  node: _ast.Const | None = None,
@@ -336,7 +361,11 @@ class Docstring(_Stub):
336
361
  self._string = None
337
362
  if node is not None:
338
363
  self._string = _RawDocstring(node.value)
339
- for i in _Matches(self._string, self._indent_anomaly(node.value)):
364
+ for i in _Matches(
365
+ self._string,
366
+ self._indent_anomaly(node.value),
367
+ self._missing_descriptions(node.value),
368
+ ):
340
369
  self._args.append(i)
341
370
 
342
371
  self._returns = self._string is not None and bool(
@@ -8,4 +8,4 @@ Allows for access to the version internally without cyclic imports
8
8
  caused by accessing it through __init__.
9
9
  """
10
10
 
11
- __version__ = "0.53.3"
11
+ __version__ = "0.54.0"
@@ -1,26 +1,6 @@
1
1
  """
2
2
  docsig.messages
3
3
  ===============
4
- | E101: parameters out of order
5
- | E102: includes parameters that do not exist
6
- | E103: parameters missing
7
- | E104: return statement documented for None
8
- | E105: return missing from docstring
9
- | E106: duplicate parameters found
10
- | E107: parameter appears to be incorrectly documented
11
- | E108: return statement documented for property
12
- | E109: cannot determine whether a return statement should exist or not
13
- | E110: documented parameter not equal to its respective argument
14
- | E111: return statement documented for class
15
- | E112: spelling error found in documented parameter
16
- | E113: function is missing a docstring
17
- | E114: class is missing a docstring
18
- | E115: syntax error in description
19
- | E116: param not indented correctly
20
- | E201: unknown module comment directive '{directive}'
21
- | E202: unknown inline comment directive '{directive}'
22
- | E203: unknown module comment option for {directive} '{option}'
23
- | E204: unknown inline comment option for {directive} '{option}'
24
4
  """
25
5
 
26
6
  from __future__ import annotations
@@ -157,7 +137,7 @@ E = MessageMap(
157
137
  ),
158
138
  109: Message(
159
139
  "E109",
160
- "cannot determine whether a return statement should exist or not",
140
+ "cannot determine whether a return statement should exist",
161
141
  "confirm-return-needed",
162
142
  "annotate type to indicate whether return documentation needed",
163
143
  ),
@@ -197,6 +177,11 @@ E = MessageMap(
197
177
  "param not indented correctly",
198
178
  "incorrect-indent",
199
179
  ),
180
+ 117: Message(
181
+ "E117",
182
+ "description missing from parameter",
183
+ "description-missing",
184
+ ),
200
185
  # E2xx: Config
201
186
  201: Message(
202
187
  "E201",
@@ -76,7 +76,7 @@ maintainers = [
76
76
  name = "docsig"
77
77
  readme = "README.rst"
78
78
  repository = "https://github.com/jshwi/docsig"
79
- version = "0.53.3"
79
+ version = "0.54.0"
80
80
 
81
81
  [tool.poetry.dependencies]
82
82
  Sphinx = "^7.0.0"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes