docstringify 0.4.0__tar.gz → 0.5.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.
- {docstringify-0.4.0/src/docstringify.egg-info → docstringify-0.5.0}/PKG-INFO +5 -5
- {docstringify-0.4.0 → docstringify-0.5.0}/README.md +4 -4
- {docstringify-0.4.0 → docstringify-0.5.0}/src/docstringify/__init__.py +1 -1
- {docstringify-0.4.0 → docstringify-0.5.0}/src/docstringify/cli.py +1 -1
- {docstringify-0.4.0 → docstringify-0.5.0}/src/docstringify/converters/base.py +10 -12
- {docstringify-0.4.0 → docstringify-0.5.0}/src/docstringify/converters/google.py +14 -4
- {docstringify-0.4.0 → docstringify-0.5.0}/src/docstringify/converters/numpydoc.py +14 -4
- {docstringify-0.4.0 → docstringify-0.5.0}/src/docstringify/nodes/base.py +4 -1
- {docstringify-0.4.0 → docstringify-0.5.0}/src/docstringify/nodes/function.py +9 -0
- {docstringify-0.4.0 → docstringify-0.5.0}/src/docstringify/traversal/transformer.py +1 -4
- {docstringify-0.4.0 → docstringify-0.5.0}/src/docstringify/traversal/visitor.py +1 -2
- {docstringify-0.4.0 → docstringify-0.5.0/src/docstringify.egg-info}/PKG-INFO +5 -5
- {docstringify-0.4.0 → docstringify-0.5.0}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
- {docstringify-0.4.0 → docstringify-0.5.0}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
- {docstringify-0.4.0 → docstringify-0.5.0}/.github/dependabot.yml +0 -0
- {docstringify-0.4.0 → docstringify-0.5.0}/.github/release.yml +0 -0
- {docstringify-0.4.0 → docstringify-0.5.0}/.github/workflows/ci.yml +0 -0
- {docstringify-0.4.0 → docstringify-0.5.0}/.github/workflows/greetings.yml +0 -0
- {docstringify-0.4.0 → docstringify-0.5.0}/.github/workflows/pypi-publish.yml +0 -0
- {docstringify-0.4.0 → docstringify-0.5.0}/.gitignore +0 -0
- {docstringify-0.4.0 → docstringify-0.5.0}/.pre-commit-config.yaml +0 -0
- {docstringify-0.4.0 → docstringify-0.5.0}/.pre-commit-hooks.yaml +0 -0
- {docstringify-0.4.0 → docstringify-0.5.0}/LICENSE +0 -0
- {docstringify-0.4.0 → docstringify-0.5.0}/pyproject.toml +0 -0
- {docstringify-0.4.0 → docstringify-0.5.0}/setup.cfg +0 -0
- {docstringify-0.4.0 → docstringify-0.5.0}/src/docstringify/__main__.py +0 -0
- {docstringify-0.4.0 → docstringify-0.5.0}/src/docstringify/components.py +0 -0
- {docstringify-0.4.0 → docstringify-0.5.0}/src/docstringify/converters/__init__.py +0 -0
- {docstringify-0.4.0 → docstringify-0.5.0}/src/docstringify/exceptions.py +0 -0
- {docstringify-0.4.0 → docstringify-0.5.0}/src/docstringify/nodes/__init__.py +0 -0
- {docstringify-0.4.0 → docstringify-0.5.0}/src/docstringify/traversal/__init__.py +0 -0
- {docstringify-0.4.0 → docstringify-0.5.0}/src/docstringify.egg-info/SOURCES.txt +0 -0
- {docstringify-0.4.0 → docstringify-0.5.0}/src/docstringify.egg-info/dependency_links.txt +0 -0
- {docstringify-0.4.0 → docstringify-0.5.0}/src/docstringify.egg-info/entry_points.txt +0 -0
- {docstringify-0.4.0 → docstringify-0.5.0}/src/docstringify.egg-info/requires.txt +0 -0
- {docstringify-0.4.0 → docstringify-0.5.0}/src/docstringify.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: docstringify
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Summary: Flag missing docstrings and, optionally, generate them from signatures and type annotations.
|
|
5
5
|
Author-email: Stefanie Molin <docstringify@stefaniemolin.com>
|
|
6
6
|
License: MIT License
|
|
@@ -60,7 +60,7 @@ Add the following to your `.pre-commit-config.yaml` file to block commits with m
|
|
|
60
60
|
|
|
61
61
|
```yaml
|
|
62
62
|
- repo: https://github.com/stefmolin/docstringify
|
|
63
|
-
rev: 0.
|
|
63
|
+
rev: 0.5.0
|
|
64
64
|
hooks:
|
|
65
65
|
- id: docstringify
|
|
66
66
|
```
|
|
@@ -69,7 +69,7 @@ By default, all docstrings are required. If you want to be more lenient, you can
|
|
|
69
69
|
|
|
70
70
|
```yaml
|
|
71
71
|
- repo: https://github.com/stefmolin/docstringify
|
|
72
|
-
rev: 0.
|
|
72
|
+
rev: 0.5.0
|
|
73
73
|
hooks:
|
|
74
74
|
- id: docstringify
|
|
75
75
|
args: [--threshold=0.75]
|
|
@@ -79,7 +79,7 @@ If you would like to see suggested docstring templates (inferred from type annot
|
|
|
79
79
|
|
|
80
80
|
```yaml
|
|
81
81
|
- repo: https://github.com/stefmolin/docstringify
|
|
82
|
-
rev: 0.
|
|
82
|
+
rev: 0.5.0
|
|
83
83
|
hooks:
|
|
84
84
|
- id: docstringify
|
|
85
85
|
args: [--suggest-changes=numpydoc]
|
|
@@ -89,7 +89,7 @@ Use `--make-changes` to create a copy of each file with docstring templates. Her
|
|
|
89
89
|
|
|
90
90
|
```yaml
|
|
91
91
|
- repo: https://github.com/stefmolin/docstringify
|
|
92
|
-
rev: 0.
|
|
92
|
+
rev: 0.5.0
|
|
93
93
|
hooks:
|
|
94
94
|
- id: docstringify
|
|
95
95
|
args: [--make-changes=google]
|
|
@@ -9,7 +9,7 @@ Add the following to your `.pre-commit-config.yaml` file to block commits with m
|
|
|
9
9
|
|
|
10
10
|
```yaml
|
|
11
11
|
- repo: https://github.com/stefmolin/docstringify
|
|
12
|
-
rev: 0.
|
|
12
|
+
rev: 0.5.0
|
|
13
13
|
hooks:
|
|
14
14
|
- id: docstringify
|
|
15
15
|
```
|
|
@@ -18,7 +18,7 @@ By default, all docstrings are required. If you want to be more lenient, you can
|
|
|
18
18
|
|
|
19
19
|
```yaml
|
|
20
20
|
- repo: https://github.com/stefmolin/docstringify
|
|
21
|
-
rev: 0.
|
|
21
|
+
rev: 0.5.0
|
|
22
22
|
hooks:
|
|
23
23
|
- id: docstringify
|
|
24
24
|
args: [--threshold=0.75]
|
|
@@ -28,7 +28,7 @@ If you would like to see suggested docstring templates (inferred from type annot
|
|
|
28
28
|
|
|
29
29
|
```yaml
|
|
30
30
|
- repo: https://github.com/stefmolin/docstringify
|
|
31
|
-
rev: 0.
|
|
31
|
+
rev: 0.5.0
|
|
32
32
|
hooks:
|
|
33
33
|
- id: docstringify
|
|
34
34
|
args: [--suggest-changes=numpydoc]
|
|
@@ -38,7 +38,7 @@ Use `--make-changes` to create a copy of each file with docstring templates. Her
|
|
|
38
38
|
|
|
39
39
|
```yaml
|
|
40
40
|
- repo: https://github.com/stefmolin/docstringify
|
|
41
|
-
rev: 0.
|
|
41
|
+
rev: 0.5.0
|
|
42
42
|
hooks:
|
|
43
43
|
- id: docstringify
|
|
44
44
|
args: [--make-changes=google]
|
|
@@ -76,7 +76,7 @@ def main(argv: Sequence[str] | None = None) -> int:
|
|
|
76
76
|
for file in args.filenames:
|
|
77
77
|
processor = get_docstring_processor(file)
|
|
78
78
|
processor.process_file()
|
|
79
|
-
missing_docstrings += processor.missing_docstrings
|
|
79
|
+
missing_docstrings += len(processor.missing_docstrings)
|
|
80
80
|
docstrings_processed += processor.docstrings_inspected
|
|
81
81
|
|
|
82
82
|
if docstrings_processed and (
|
|
@@ -7,7 +7,6 @@ import textwrap
|
|
|
7
7
|
from abc import ABC, abstractmethod
|
|
8
8
|
from typing import TYPE_CHECKING
|
|
9
9
|
|
|
10
|
-
from ..components import Function
|
|
11
10
|
from ..exceptions import InvalidDocstringError
|
|
12
11
|
|
|
13
12
|
if TYPE_CHECKING:
|
|
@@ -27,15 +26,15 @@ class DocstringConverter(ABC):
|
|
|
27
26
|
self._quote = quote
|
|
28
27
|
|
|
29
28
|
@abstractmethod
|
|
30
|
-
def to_class_docstring(self,
|
|
29
|
+
def to_class_docstring(self, docstring_node: DocstringNode, indent: int) -> str:
|
|
31
30
|
pass
|
|
32
31
|
|
|
33
32
|
@abstractmethod
|
|
34
|
-
def to_function_docstring(self,
|
|
33
|
+
def to_function_docstring(self, docstring_node: DocstringNode, indent: int) -> str:
|
|
35
34
|
pass
|
|
36
35
|
|
|
37
36
|
@abstractmethod
|
|
38
|
-
def to_module_docstring(self,
|
|
37
|
+
def to_module_docstring(self, docstring_node: DocstringNode) -> str:
|
|
39
38
|
pass
|
|
40
39
|
|
|
41
40
|
@abstractmethod
|
|
@@ -79,16 +78,15 @@ class DocstringConverter(ABC):
|
|
|
79
78
|
self,
|
|
80
79
|
docstring_node: DocstringNode,
|
|
81
80
|
indent: int = 0,
|
|
82
|
-
) -> str:
|
|
81
|
+
) -> str | None:
|
|
83
82
|
if isinstance(docstring_node.ast_node, ast.AsyncFunctionDef | ast.FunctionDef):
|
|
84
|
-
return
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
indent=indent,
|
|
83
|
+
return (
|
|
84
|
+
self.to_function_docstring(docstring_node, indent=indent)
|
|
85
|
+
if docstring_node.docstring_required
|
|
86
|
+
else None
|
|
89
87
|
)
|
|
90
88
|
|
|
91
89
|
if isinstance(docstring_node.ast_node, ast.Module):
|
|
92
|
-
return self.to_module_docstring(docstring_node
|
|
90
|
+
return self.to_module_docstring(docstring_node)
|
|
93
91
|
|
|
94
|
-
return self.to_class_docstring(docstring_node
|
|
92
|
+
return self.to_class_docstring(docstring_node, indent=indent)
|
|
@@ -2,9 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
from
|
|
5
|
+
from typing import TYPE_CHECKING
|
|
6
|
+
|
|
7
|
+
from ..components import DESCRIPTION_PLACEHOLDER, NO_DEFAULT, Parameter
|
|
6
8
|
from .base import DocstringConverter
|
|
7
9
|
|
|
10
|
+
if TYPE_CHECKING:
|
|
11
|
+
from ..nodes.base import DocstringNode
|
|
12
|
+
from ..nodes.function import FunctionDocstringNode
|
|
13
|
+
|
|
8
14
|
|
|
9
15
|
class GoogleDocstringConverter(DocstringConverter):
|
|
10
16
|
def __init__(self, quote: bool) -> None:
|
|
@@ -14,7 +20,11 @@ class GoogleDocstringConverter(DocstringConverter):
|
|
|
14
20
|
quote=quote,
|
|
15
21
|
)
|
|
16
22
|
|
|
17
|
-
def to_function_docstring(
|
|
23
|
+
def to_function_docstring(
|
|
24
|
+
self, docstring_node: FunctionDocstringNode, indent: int
|
|
25
|
+
) -> str:
|
|
26
|
+
function = docstring_node.to_function()
|
|
27
|
+
|
|
18
28
|
docstring = [DESCRIPTION_PLACEHOLDER]
|
|
19
29
|
|
|
20
30
|
if parameters_section := self.parameters_section(function.parameters):
|
|
@@ -37,8 +47,8 @@ class GoogleDocstringConverter(DocstringConverter):
|
|
|
37
47
|
return f'{return_type}: {DESCRIPTION_PLACEHOLDER}'
|
|
38
48
|
return ''
|
|
39
49
|
|
|
40
|
-
def to_module_docstring(self,
|
|
50
|
+
def to_module_docstring(self, docstring_node: DocstringNode) -> str:
|
|
41
51
|
return self.quote_docstring(DESCRIPTION_PLACEHOLDER, indent=0)
|
|
42
52
|
|
|
43
|
-
def to_class_docstring(self,
|
|
53
|
+
def to_class_docstring(self, docstring_node: DocstringNode, indent: int) -> str:
|
|
44
54
|
return self.quote_docstring(DESCRIPTION_PLACEHOLDER, indent=indent)
|
|
@@ -2,9 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
from
|
|
5
|
+
from typing import TYPE_CHECKING
|
|
6
|
+
|
|
7
|
+
from ..components import DESCRIPTION_PLACEHOLDER, NO_DEFAULT, Parameter
|
|
6
8
|
from .base import DocstringConverter
|
|
7
9
|
|
|
10
|
+
if TYPE_CHECKING:
|
|
11
|
+
from ..nodes.base import DocstringNode
|
|
12
|
+
from ..nodes.function import FunctionDocstringNode
|
|
13
|
+
|
|
8
14
|
|
|
9
15
|
class NumpydocDocstringConverter(DocstringConverter):
|
|
10
16
|
def __init__(self, quote: bool) -> None:
|
|
@@ -14,7 +20,11 @@ class NumpydocDocstringConverter(DocstringConverter):
|
|
|
14
20
|
quote=quote,
|
|
15
21
|
)
|
|
16
22
|
|
|
17
|
-
def to_function_docstring(
|
|
23
|
+
def to_function_docstring(
|
|
24
|
+
self, docstring_node: FunctionDocstringNode, indent: int
|
|
25
|
+
) -> str:
|
|
26
|
+
function = docstring_node.to_function()
|
|
27
|
+
|
|
18
28
|
docstring = [DESCRIPTION_PLACEHOLDER]
|
|
19
29
|
|
|
20
30
|
if parameters_section := self.parameters_section(function.parameters):
|
|
@@ -38,8 +48,8 @@ class NumpydocDocstringConverter(DocstringConverter):
|
|
|
38
48
|
return f'{return_type}\n {DESCRIPTION_PLACEHOLDER}'
|
|
39
49
|
return ''
|
|
40
50
|
|
|
41
|
-
def to_module_docstring(self,
|
|
51
|
+
def to_module_docstring(self, docstring_node: DocstringNode) -> str:
|
|
42
52
|
return self.quote_docstring(DESCRIPTION_PLACEHOLDER, indent=0)
|
|
43
53
|
|
|
44
|
-
def to_class_docstring(self,
|
|
54
|
+
def to_class_docstring(self, docstring_node: DocstringNode, indent: int) -> str:
|
|
45
55
|
return self.quote_docstring(DESCRIPTION_PLACEHOLDER, indent=indent)
|
|
@@ -33,13 +33,16 @@ class DocstringNode:
|
|
|
33
33
|
) -> None:
|
|
34
34
|
self.module_name: str = module_name
|
|
35
35
|
self.parent: DocstringNode | None = parent
|
|
36
|
+
self.docstring_required: bool = True
|
|
36
37
|
|
|
37
38
|
self.ast_node: (
|
|
38
39
|
ast.Module | ast.ClassDef | ast.FunctionDef | ast.AsyncFunctionDef
|
|
39
40
|
) = node
|
|
40
41
|
self.name: str = getattr(node, 'name', self.module_name)
|
|
41
42
|
|
|
42
|
-
|
|
43
|
+
docstring = ast.get_docstring(node)
|
|
44
|
+
self.docstring = docstring if docstring is None else docstring.strip()
|
|
45
|
+
|
|
43
46
|
self.get_source_segment: Callable[[ast.AST], str] = partial(
|
|
44
47
|
ast.get_source_segment, source_code
|
|
45
48
|
)
|
|
@@ -8,6 +8,7 @@ from ..components import (
|
|
|
8
8
|
NO_DEFAULT,
|
|
9
9
|
PARAMETER_TYPE_PLACEHOLDER,
|
|
10
10
|
RETURN_TYPE_PLACEHOLDER,
|
|
11
|
+
Function,
|
|
11
12
|
Parameter,
|
|
12
13
|
)
|
|
13
14
|
from .base import DocstringNode
|
|
@@ -41,6 +42,11 @@ class FunctionDocstringNode(DocstringNode):
|
|
|
41
42
|
self.is_method and not self.is_class_method and not self.is_static_method
|
|
42
43
|
)
|
|
43
44
|
|
|
45
|
+
# don't require docstring for the __init__ method if the class has a docstring
|
|
46
|
+
self.docstring_required: bool = not (
|
|
47
|
+
self.is_method and self.name == '__init__' and self.parent.docstring
|
|
48
|
+
)
|
|
49
|
+
|
|
44
50
|
self.arguments: ast.arguments | None = getattr(node, 'args', None)
|
|
45
51
|
self.return_annotation: str | None = self._extract_return_annotation()
|
|
46
52
|
self.return_statements: list[ast.Return] = []
|
|
@@ -157,3 +163,6 @@ class FunctionDocstringNode(DocstringNode):
|
|
|
157
163
|
):
|
|
158
164
|
return RETURN_TYPE_PLACEHOLDER
|
|
159
165
|
return None
|
|
166
|
+
|
|
167
|
+
def to_function(self) -> Function:
|
|
168
|
+
return Function(self.extract_arguments(), self.extract_returns())
|
|
@@ -45,10 +45,7 @@ class DocstringTransformer(ast.NodeTransformer, DocstringVisitor):
|
|
|
45
45
|
)
|
|
46
46
|
docstring_ast_node = ast.Expr(ast.Constant(suggested_docstring))
|
|
47
47
|
|
|
48
|
-
if
|
|
49
|
-
docstring_node.docstring is not None
|
|
50
|
-
and docstring_node.docstring.strip() == ''
|
|
51
|
-
):
|
|
48
|
+
if docstring_node.docstring is not None:
|
|
52
49
|
# If the docstring is empty, we replace it with the suggested docstring
|
|
53
50
|
docstring_node.ast_node.body[0] = docstring_ast_node
|
|
54
51
|
else:
|
|
@@ -37,7 +37,6 @@ class DocstringVisitor(ast.NodeVisitor):
|
|
|
37
37
|
print(f'No missing docstrings found in {self.source_file}.')
|
|
38
38
|
else:
|
|
39
39
|
for docstring_node in self.missing_docstrings:
|
|
40
|
-
# TODO: need to print full path for node name
|
|
41
40
|
print(
|
|
42
41
|
f'{docstring_node.fully_qualified_name} is missing a docstring',
|
|
43
42
|
file=sys.stderr,
|
|
@@ -51,7 +50,7 @@ class DocstringVisitor(ast.NodeVisitor):
|
|
|
51
50
|
print()
|
|
52
51
|
|
|
53
52
|
def process_docstring(self, docstring_node: DocstringNode) -> DocstringNode:
|
|
54
|
-
if docstring_node.
|
|
53
|
+
if docstring_node.docstring_required and not docstring_node.docstring:
|
|
55
54
|
self.missing_docstrings.append(docstring_node)
|
|
56
55
|
|
|
57
56
|
self.docstrings_inspected += 1
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: docstringify
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.0
|
|
4
4
|
Summary: Flag missing docstrings and, optionally, generate them from signatures and type annotations.
|
|
5
5
|
Author-email: Stefanie Molin <docstringify@stefaniemolin.com>
|
|
6
6
|
License: MIT License
|
|
@@ -60,7 +60,7 @@ Add the following to your `.pre-commit-config.yaml` file to block commits with m
|
|
|
60
60
|
|
|
61
61
|
```yaml
|
|
62
62
|
- repo: https://github.com/stefmolin/docstringify
|
|
63
|
-
rev: 0.
|
|
63
|
+
rev: 0.5.0
|
|
64
64
|
hooks:
|
|
65
65
|
- id: docstringify
|
|
66
66
|
```
|
|
@@ -69,7 +69,7 @@ By default, all docstrings are required. If you want to be more lenient, you can
|
|
|
69
69
|
|
|
70
70
|
```yaml
|
|
71
71
|
- repo: https://github.com/stefmolin/docstringify
|
|
72
|
-
rev: 0.
|
|
72
|
+
rev: 0.5.0
|
|
73
73
|
hooks:
|
|
74
74
|
- id: docstringify
|
|
75
75
|
args: [--threshold=0.75]
|
|
@@ -79,7 +79,7 @@ If you would like to see suggested docstring templates (inferred from type annot
|
|
|
79
79
|
|
|
80
80
|
```yaml
|
|
81
81
|
- repo: https://github.com/stefmolin/docstringify
|
|
82
|
-
rev: 0.
|
|
82
|
+
rev: 0.5.0
|
|
83
83
|
hooks:
|
|
84
84
|
- id: docstringify
|
|
85
85
|
args: [--suggest-changes=numpydoc]
|
|
@@ -89,7 +89,7 @@ Use `--make-changes` to create a copy of each file with docstring templates. Her
|
|
|
89
89
|
|
|
90
90
|
```yaml
|
|
91
91
|
- repo: https://github.com/stefmolin/docstringify
|
|
92
|
-
rev: 0.
|
|
92
|
+
rev: 0.5.0
|
|
93
93
|
hooks:
|
|
94
94
|
- id: docstringify
|
|
95
95
|
args: [--make-changes=google]
|
|
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
|
|
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
|