docstringify 0.4.0__tar.gz → 0.5.1__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 → docstringify-0.5.1}/PKG-INFO +59 -6
- {docstringify-0.4.0 → docstringify-0.5.1}/README.md +58 -5
- {docstringify-0.4.0 → docstringify-0.5.1}/src/docstringify/__init__.py +1 -1
- {docstringify-0.4.0 → docstringify-0.5.1}/src/docstringify/cli.py +1 -1
- {docstringify-0.4.0 → docstringify-0.5.1}/src/docstringify/converters/base.py +10 -12
- {docstringify-0.4.0 → docstringify-0.5.1}/src/docstringify/converters/google.py +14 -4
- {docstringify-0.4.0 → docstringify-0.5.1}/src/docstringify/converters/numpydoc.py +14 -4
- {docstringify-0.4.0 → docstringify-0.5.1}/src/docstringify/nodes/base.py +4 -1
- {docstringify-0.4.0 → docstringify-0.5.1}/src/docstringify/nodes/function.py +9 -0
- {docstringify-0.4.0 → docstringify-0.5.1}/src/docstringify/traversal/transformer.py +1 -4
- {docstringify-0.4.0 → docstringify-0.5.1}/src/docstringify/traversal/visitor.py +1 -2
- {docstringify-0.4.0 → docstringify-0.5.1}/src/docstringify.egg-info/PKG-INFO +59 -6
- {docstringify-0.4.0 → docstringify-0.5.1}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
- {docstringify-0.4.0 → docstringify-0.5.1}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
- {docstringify-0.4.0 → docstringify-0.5.1}/.github/dependabot.yml +0 -0
- {docstringify-0.4.0 → docstringify-0.5.1}/.github/release.yml +0 -0
- {docstringify-0.4.0 → docstringify-0.5.1}/.github/workflows/ci.yml +0 -0
- {docstringify-0.4.0 → docstringify-0.5.1}/.github/workflows/greetings.yml +0 -0
- {docstringify-0.4.0 → docstringify-0.5.1}/.github/workflows/pypi-publish.yml +0 -0
- {docstringify-0.4.0 → docstringify-0.5.1}/.gitignore +0 -0
- {docstringify-0.4.0 → docstringify-0.5.1}/.pre-commit-config.yaml +0 -0
- {docstringify-0.4.0 → docstringify-0.5.1}/.pre-commit-hooks.yaml +0 -0
- {docstringify-0.4.0 → docstringify-0.5.1}/LICENSE +0 -0
- {docstringify-0.4.0 → docstringify-0.5.1}/pyproject.toml +0 -0
- {docstringify-0.4.0 → docstringify-0.5.1}/setup.cfg +0 -0
- {docstringify-0.4.0 → docstringify-0.5.1}/src/docstringify/__main__.py +0 -0
- {docstringify-0.4.0 → docstringify-0.5.1}/src/docstringify/components.py +0 -0
- {docstringify-0.4.0 → docstringify-0.5.1}/src/docstringify/converters/__init__.py +0 -0
- {docstringify-0.4.0 → docstringify-0.5.1}/src/docstringify/exceptions.py +0 -0
- {docstringify-0.4.0 → docstringify-0.5.1}/src/docstringify/nodes/__init__.py +0 -0
- {docstringify-0.4.0 → docstringify-0.5.1}/src/docstringify/traversal/__init__.py +0 -0
- {docstringify-0.4.0 → docstringify-0.5.1}/src/docstringify.egg-info/SOURCES.txt +0 -0
- {docstringify-0.4.0 → docstringify-0.5.1}/src/docstringify.egg-info/dependency_links.txt +0 -0
- {docstringify-0.4.0 → docstringify-0.5.1}/src/docstringify.egg-info/entry_points.txt +0 -0
- {docstringify-0.4.0 → docstringify-0.5.1}/src/docstringify.egg-info/requires.txt +0 -0
- {docstringify-0.4.0 → docstringify-0.5.1}/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.1
|
|
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
|
|
@@ -49,9 +49,58 @@ Requires-Dist: pytest-cov; extra == "dev"
|
|
|
49
49
|
Requires-Dist: pytest-randomly; extra == "dev"
|
|
50
50
|
Dynamic: license-file
|
|
51
51
|
|
|
52
|
-
#
|
|
52
|
+
# Docstringify
|
|
53
53
|
Flag missing docstrings and, optionally, generate them from signatures and type annotations.
|
|
54
54
|
|
|
55
|
+
## About
|
|
56
|
+
|
|
57
|
+
Given a file, `test.py`, with the following contents:
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
def say_hello(name: str = 'World') -> None:
|
|
61
|
+
print(f'Hello, {name}!')
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
You can use Docstringify in three modes:
|
|
65
|
+
|
|
66
|
+
1. Flag missing docstrings:
|
|
67
|
+
```
|
|
68
|
+
test is missing a docstring
|
|
69
|
+
test.say_hello is missing a docstring
|
|
70
|
+
```
|
|
71
|
+
2. Suggest docstring templates based on type annotations:
|
|
72
|
+
```
|
|
73
|
+
test is missing a docstring
|
|
74
|
+
Hint:
|
|
75
|
+
"""__description__"""
|
|
76
|
+
|
|
77
|
+
test.say_hello is missing a docstring
|
|
78
|
+
Hint:
|
|
79
|
+
"""
|
|
80
|
+
__description__
|
|
81
|
+
|
|
82
|
+
Parameters
|
|
83
|
+
----------
|
|
84
|
+
name : str, default="World"
|
|
85
|
+
__description__
|
|
86
|
+
"""
|
|
87
|
+
```
|
|
88
|
+
3. Add docstring templates to source code files:
|
|
89
|
+
```python
|
|
90
|
+
"""__description__"""
|
|
91
|
+
|
|
92
|
+
def say_hello(name: str = 'World') -> None:
|
|
93
|
+
"""
|
|
94
|
+
__description__
|
|
95
|
+
|
|
96
|
+
Parameters
|
|
97
|
+
----------
|
|
98
|
+
name : str, default="World"
|
|
99
|
+
__description__
|
|
100
|
+
"""
|
|
101
|
+
print(f'Hello, {name}!')
|
|
102
|
+
```
|
|
103
|
+
|
|
55
104
|
## Usage
|
|
56
105
|
|
|
57
106
|
### Pre-commit hook
|
|
@@ -60,7 +109,7 @@ Add the following to your `.pre-commit-config.yaml` file to block commits with m
|
|
|
60
109
|
|
|
61
110
|
```yaml
|
|
62
111
|
- repo: https://github.com/stefmolin/docstringify
|
|
63
|
-
rev: 0.
|
|
112
|
+
rev: 0.5.1
|
|
64
113
|
hooks:
|
|
65
114
|
- id: docstringify
|
|
66
115
|
```
|
|
@@ -69,7 +118,7 @@ By default, all docstrings are required. If you want to be more lenient, you can
|
|
|
69
118
|
|
|
70
119
|
```yaml
|
|
71
120
|
- repo: https://github.com/stefmolin/docstringify
|
|
72
|
-
rev: 0.
|
|
121
|
+
rev: 0.5.1
|
|
73
122
|
hooks:
|
|
74
123
|
- id: docstringify
|
|
75
124
|
args: [--threshold=0.75]
|
|
@@ -79,7 +128,7 @@ If you would like to see suggested docstring templates (inferred from type annot
|
|
|
79
128
|
|
|
80
129
|
```yaml
|
|
81
130
|
- repo: https://github.com/stefmolin/docstringify
|
|
82
|
-
rev: 0.
|
|
131
|
+
rev: 0.5.1
|
|
83
132
|
hooks:
|
|
84
133
|
- id: docstringify
|
|
85
134
|
args: [--suggest-changes=numpydoc]
|
|
@@ -89,7 +138,7 @@ Use `--make-changes` to create a copy of each file with docstring templates. Her
|
|
|
89
138
|
|
|
90
139
|
```yaml
|
|
91
140
|
- repo: https://github.com/stefmolin/docstringify
|
|
92
|
-
rev: 0.
|
|
141
|
+
rev: 0.5.1
|
|
93
142
|
hooks:
|
|
94
143
|
- id: docstringify
|
|
95
144
|
args: [--make-changes=google]
|
|
@@ -170,3 +219,7 @@ Docstring templates written to /.../test_docstringify.py
|
|
|
170
219
|
```
|
|
171
220
|
|
|
172
221
|
If you want to overwrite the file with the edits, pass `overwrite=True` to `DocstringTransformer()`.
|
|
222
|
+
|
|
223
|
+
## Contributing
|
|
224
|
+
|
|
225
|
+
Please consult the [contributing guidelines](https://github.com/stefmolin/docstringify/blob/main/CONTRIBUTING.md).
|
|
@@ -1,6 +1,55 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Docstringify
|
|
2
2
|
Flag missing docstrings and, optionally, generate them from signatures and type annotations.
|
|
3
3
|
|
|
4
|
+
## About
|
|
5
|
+
|
|
6
|
+
Given a file, `test.py`, with the following contents:
|
|
7
|
+
|
|
8
|
+
```python
|
|
9
|
+
def say_hello(name: str = 'World') -> None:
|
|
10
|
+
print(f'Hello, {name}!')
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
You can use Docstringify in three modes:
|
|
14
|
+
|
|
15
|
+
1. Flag missing docstrings:
|
|
16
|
+
```
|
|
17
|
+
test is missing a docstring
|
|
18
|
+
test.say_hello is missing a docstring
|
|
19
|
+
```
|
|
20
|
+
2. Suggest docstring templates based on type annotations:
|
|
21
|
+
```
|
|
22
|
+
test is missing a docstring
|
|
23
|
+
Hint:
|
|
24
|
+
"""__description__"""
|
|
25
|
+
|
|
26
|
+
test.say_hello is missing a docstring
|
|
27
|
+
Hint:
|
|
28
|
+
"""
|
|
29
|
+
__description__
|
|
30
|
+
|
|
31
|
+
Parameters
|
|
32
|
+
----------
|
|
33
|
+
name : str, default="World"
|
|
34
|
+
__description__
|
|
35
|
+
"""
|
|
36
|
+
```
|
|
37
|
+
3. Add docstring templates to source code files:
|
|
38
|
+
```python
|
|
39
|
+
"""__description__"""
|
|
40
|
+
|
|
41
|
+
def say_hello(name: str = 'World') -> None:
|
|
42
|
+
"""
|
|
43
|
+
__description__
|
|
44
|
+
|
|
45
|
+
Parameters
|
|
46
|
+
----------
|
|
47
|
+
name : str, default="World"
|
|
48
|
+
__description__
|
|
49
|
+
"""
|
|
50
|
+
print(f'Hello, {name}!')
|
|
51
|
+
```
|
|
52
|
+
|
|
4
53
|
## Usage
|
|
5
54
|
|
|
6
55
|
### Pre-commit hook
|
|
@@ -9,7 +58,7 @@ Add the following to your `.pre-commit-config.yaml` file to block commits with m
|
|
|
9
58
|
|
|
10
59
|
```yaml
|
|
11
60
|
- repo: https://github.com/stefmolin/docstringify
|
|
12
|
-
rev: 0.
|
|
61
|
+
rev: 0.5.1
|
|
13
62
|
hooks:
|
|
14
63
|
- id: docstringify
|
|
15
64
|
```
|
|
@@ -18,7 +67,7 @@ By default, all docstrings are required. If you want to be more lenient, you can
|
|
|
18
67
|
|
|
19
68
|
```yaml
|
|
20
69
|
- repo: https://github.com/stefmolin/docstringify
|
|
21
|
-
rev: 0.
|
|
70
|
+
rev: 0.5.1
|
|
22
71
|
hooks:
|
|
23
72
|
- id: docstringify
|
|
24
73
|
args: [--threshold=0.75]
|
|
@@ -28,7 +77,7 @@ If you would like to see suggested docstring templates (inferred from type annot
|
|
|
28
77
|
|
|
29
78
|
```yaml
|
|
30
79
|
- repo: https://github.com/stefmolin/docstringify
|
|
31
|
-
rev: 0.
|
|
80
|
+
rev: 0.5.1
|
|
32
81
|
hooks:
|
|
33
82
|
- id: docstringify
|
|
34
83
|
args: [--suggest-changes=numpydoc]
|
|
@@ -38,7 +87,7 @@ Use `--make-changes` to create a copy of each file with docstring templates. Her
|
|
|
38
87
|
|
|
39
88
|
```yaml
|
|
40
89
|
- repo: https://github.com/stefmolin/docstringify
|
|
41
|
-
rev: 0.
|
|
90
|
+
rev: 0.5.1
|
|
42
91
|
hooks:
|
|
43
92
|
- id: docstringify
|
|
44
93
|
args: [--make-changes=google]
|
|
@@ -119,3 +168,7 @@ Docstring templates written to /.../test_docstringify.py
|
|
|
119
168
|
```
|
|
120
169
|
|
|
121
170
|
If you want to overwrite the file with the edits, pass `overwrite=True` to `DocstringTransformer()`.
|
|
171
|
+
|
|
172
|
+
## Contributing
|
|
173
|
+
|
|
174
|
+
Please consult the [contributing guidelines](https://github.com/stefmolin/docstringify/blob/main/CONTRIBUTING.md).
|
|
@@ -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.1
|
|
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
|
|
@@ -49,9 +49,58 @@ Requires-Dist: pytest-cov; extra == "dev"
|
|
|
49
49
|
Requires-Dist: pytest-randomly; extra == "dev"
|
|
50
50
|
Dynamic: license-file
|
|
51
51
|
|
|
52
|
-
#
|
|
52
|
+
# Docstringify
|
|
53
53
|
Flag missing docstrings and, optionally, generate them from signatures and type annotations.
|
|
54
54
|
|
|
55
|
+
## About
|
|
56
|
+
|
|
57
|
+
Given a file, `test.py`, with the following contents:
|
|
58
|
+
|
|
59
|
+
```python
|
|
60
|
+
def say_hello(name: str = 'World') -> None:
|
|
61
|
+
print(f'Hello, {name}!')
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
You can use Docstringify in three modes:
|
|
65
|
+
|
|
66
|
+
1. Flag missing docstrings:
|
|
67
|
+
```
|
|
68
|
+
test is missing a docstring
|
|
69
|
+
test.say_hello is missing a docstring
|
|
70
|
+
```
|
|
71
|
+
2. Suggest docstring templates based on type annotations:
|
|
72
|
+
```
|
|
73
|
+
test is missing a docstring
|
|
74
|
+
Hint:
|
|
75
|
+
"""__description__"""
|
|
76
|
+
|
|
77
|
+
test.say_hello is missing a docstring
|
|
78
|
+
Hint:
|
|
79
|
+
"""
|
|
80
|
+
__description__
|
|
81
|
+
|
|
82
|
+
Parameters
|
|
83
|
+
----------
|
|
84
|
+
name : str, default="World"
|
|
85
|
+
__description__
|
|
86
|
+
"""
|
|
87
|
+
```
|
|
88
|
+
3. Add docstring templates to source code files:
|
|
89
|
+
```python
|
|
90
|
+
"""__description__"""
|
|
91
|
+
|
|
92
|
+
def say_hello(name: str = 'World') -> None:
|
|
93
|
+
"""
|
|
94
|
+
__description__
|
|
95
|
+
|
|
96
|
+
Parameters
|
|
97
|
+
----------
|
|
98
|
+
name : str, default="World"
|
|
99
|
+
__description__
|
|
100
|
+
"""
|
|
101
|
+
print(f'Hello, {name}!')
|
|
102
|
+
```
|
|
103
|
+
|
|
55
104
|
## Usage
|
|
56
105
|
|
|
57
106
|
### Pre-commit hook
|
|
@@ -60,7 +109,7 @@ Add the following to your `.pre-commit-config.yaml` file to block commits with m
|
|
|
60
109
|
|
|
61
110
|
```yaml
|
|
62
111
|
- repo: https://github.com/stefmolin/docstringify
|
|
63
|
-
rev: 0.
|
|
112
|
+
rev: 0.5.1
|
|
64
113
|
hooks:
|
|
65
114
|
- id: docstringify
|
|
66
115
|
```
|
|
@@ -69,7 +118,7 @@ By default, all docstrings are required. If you want to be more lenient, you can
|
|
|
69
118
|
|
|
70
119
|
```yaml
|
|
71
120
|
- repo: https://github.com/stefmolin/docstringify
|
|
72
|
-
rev: 0.
|
|
121
|
+
rev: 0.5.1
|
|
73
122
|
hooks:
|
|
74
123
|
- id: docstringify
|
|
75
124
|
args: [--threshold=0.75]
|
|
@@ -79,7 +128,7 @@ If you would like to see suggested docstring templates (inferred from type annot
|
|
|
79
128
|
|
|
80
129
|
```yaml
|
|
81
130
|
- repo: https://github.com/stefmolin/docstringify
|
|
82
|
-
rev: 0.
|
|
131
|
+
rev: 0.5.1
|
|
83
132
|
hooks:
|
|
84
133
|
- id: docstringify
|
|
85
134
|
args: [--suggest-changes=numpydoc]
|
|
@@ -89,7 +138,7 @@ Use `--make-changes` to create a copy of each file with docstring templates. Her
|
|
|
89
138
|
|
|
90
139
|
```yaml
|
|
91
140
|
- repo: https://github.com/stefmolin/docstringify
|
|
92
|
-
rev: 0.
|
|
141
|
+
rev: 0.5.1
|
|
93
142
|
hooks:
|
|
94
143
|
- id: docstringify
|
|
95
144
|
args: [--make-changes=google]
|
|
@@ -170,3 +219,7 @@ Docstring templates written to /.../test_docstringify.py
|
|
|
170
219
|
```
|
|
171
220
|
|
|
172
221
|
If you want to overwrite the file with the edits, pass `overwrite=True` to `DocstringTransformer()`.
|
|
222
|
+
|
|
223
|
+
## Contributing
|
|
224
|
+
|
|
225
|
+
Please consult the [contributing guidelines](https://github.com/stefmolin/docstringify/blob/main/CONTRIBUTING.md).
|
|
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
|