docstringify 0.6.0__tar.gz → 0.7.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.6.0 → docstringify-0.7.0}/.pre-commit-config.yaml +1 -1
- {docstringify-0.6.0/src/docstringify.egg-info → docstringify-0.7.0}/PKG-INFO +6 -6
- {docstringify-0.6.0 → docstringify-0.7.0}/README.md +5 -5
- {docstringify-0.6.0 → docstringify-0.7.0}/src/docstringify/__init__.py +1 -1
- {docstringify-0.6.0 → docstringify-0.7.0}/src/docstringify/cli.py +23 -12
- {docstringify-0.6.0 → docstringify-0.7.0}/src/docstringify/converters/__init__.py +2 -0
- {docstringify-0.6.0 → docstringify-0.7.0}/src/docstringify/converters/base.py +2 -2
- {docstringify-0.6.0 → docstringify-0.7.0}/src/docstringify/converters/google.py +1 -1
- {docstringify-0.6.0 → docstringify-0.7.0}/src/docstringify/converters/numpydoc.py +1 -1
- docstringify-0.7.0/src/docstringify/converters/stub.py +121 -0
- {docstringify-0.6.0 → docstringify-0.7.0}/src/docstringify/nodes/base.py +6 -4
- {docstringify-0.6.0 → docstringify-0.7.0}/src/docstringify/nodes/function.py +13 -3
- {docstringify-0.6.0 → docstringify-0.7.0}/src/docstringify/traversal/visitor.py +29 -1
- {docstringify-0.6.0 → docstringify-0.7.0/src/docstringify.egg-info}/PKG-INFO +6 -6
- {docstringify-0.6.0 → docstringify-0.7.0}/src/docstringify.egg-info/SOURCES.txt +1 -0
- {docstringify-0.6.0 → docstringify-0.7.0}/.github/ISSUE_TEMPLATE/bug_report.md +0 -0
- {docstringify-0.6.0 → docstringify-0.7.0}/.github/ISSUE_TEMPLATE/feature_request.md +0 -0
- {docstringify-0.6.0 → docstringify-0.7.0}/.github/dependabot.yml +0 -0
- {docstringify-0.6.0 → docstringify-0.7.0}/.github/pull_request_template.md +0 -0
- {docstringify-0.6.0 → docstringify-0.7.0}/.github/release.yml +0 -0
- {docstringify-0.6.0 → docstringify-0.7.0}/.github/workflows/ci.yml +0 -0
- {docstringify-0.6.0 → docstringify-0.7.0}/.github/workflows/greetings.yml +0 -0
- {docstringify-0.6.0 → docstringify-0.7.0}/.github/workflows/pypi-publish.yml +0 -0
- {docstringify-0.6.0 → docstringify-0.7.0}/.gitignore +0 -0
- {docstringify-0.6.0 → docstringify-0.7.0}/.pre-commit-hooks.yaml +0 -0
- {docstringify-0.6.0 → docstringify-0.7.0}/CODE_OF_CONDUCT.md +0 -0
- {docstringify-0.6.0 → docstringify-0.7.0}/CONTRIBUTING.md +0 -0
- {docstringify-0.6.0 → docstringify-0.7.0}/LICENSE +0 -0
- {docstringify-0.6.0 → docstringify-0.7.0}/pyproject.toml +0 -0
- {docstringify-0.6.0 → docstringify-0.7.0}/setup.cfg +0 -0
- {docstringify-0.6.0 → docstringify-0.7.0}/src/docstringify/__main__.py +0 -0
- {docstringify-0.6.0 → docstringify-0.7.0}/src/docstringify/components.py +0 -0
- {docstringify-0.6.0 → docstringify-0.7.0}/src/docstringify/exceptions.py +0 -0
- {docstringify-0.6.0 → docstringify-0.7.0}/src/docstringify/nodes/__init__.py +0 -0
- {docstringify-0.6.0 → docstringify-0.7.0}/src/docstringify/traversal/__init__.py +0 -0
- {docstringify-0.6.0 → docstringify-0.7.0}/src/docstringify/traversal/transformer.py +0 -0
- {docstringify-0.6.0 → docstringify-0.7.0}/src/docstringify.egg-info/dependency_links.txt +0 -0
- {docstringify-0.6.0 → docstringify-0.7.0}/src/docstringify.egg-info/entry_points.txt +0 -0
- {docstringify-0.6.0 → docstringify-0.7.0}/src/docstringify.egg-info/requires.txt +0 -0
- {docstringify-0.6.0 → docstringify-0.7.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.7.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
|
|
@@ -107,7 +107,7 @@ Add the following to your `.pre-commit-config.yaml` file to block commits with m
|
|
|
107
107
|
|
|
108
108
|
```yaml
|
|
109
109
|
- repo: https://github.com/stefmolin/docstringify
|
|
110
|
-
rev: 0.
|
|
110
|
+
rev: 0.7.0
|
|
111
111
|
hooks:
|
|
112
112
|
- id: docstringify
|
|
113
113
|
```
|
|
@@ -116,17 +116,17 @@ By default, all docstrings are required. If you want to be more lenient, you can
|
|
|
116
116
|
|
|
117
117
|
```yaml
|
|
118
118
|
- repo: https://github.com/stefmolin/docstringify
|
|
119
|
-
rev: 0.
|
|
119
|
+
rev: 0.7.0
|
|
120
120
|
hooks:
|
|
121
121
|
- id: docstringify
|
|
122
122
|
args: [--threshold=0.75]
|
|
123
123
|
```
|
|
124
124
|
|
|
125
|
-
If you would like to see suggested docstring templates (inferred from type annotations for functions and methods), provide the `--suggest-changes` argument, along with the docstring style you want to use (options are `google` and `
|
|
125
|
+
If you would like to see suggested docstring templates (inferred from type annotations for functions and methods), provide the `--suggest-changes` argument, along with the docstring style you want to use (options are `google`, `numpydoc`, and `stub`). Here, we ask for [numpydoc-style docstring](https://numpydoc.readthedocs.io/en/latest/format.html#) suggestions:
|
|
126
126
|
|
|
127
127
|
```yaml
|
|
128
128
|
- repo: https://github.com/stefmolin/docstringify
|
|
129
|
-
rev: 0.
|
|
129
|
+
rev: 0.7.0
|
|
130
130
|
hooks:
|
|
131
131
|
- id: docstringify
|
|
132
132
|
args: [--suggest-changes=numpydoc]
|
|
@@ -136,7 +136,7 @@ Use `--make-changes` to create a copy of each file with docstring templates. Her
|
|
|
136
136
|
|
|
137
137
|
```yaml
|
|
138
138
|
- repo: https://github.com/stefmolin/docstringify
|
|
139
|
-
rev: 0.
|
|
139
|
+
rev: 0.7.0
|
|
140
140
|
hooks:
|
|
141
141
|
- id: docstringify
|
|
142
142
|
args: [--make-changes=google]
|
|
@@ -58,7 +58,7 @@ Add the following to your `.pre-commit-config.yaml` file to block commits with m
|
|
|
58
58
|
|
|
59
59
|
```yaml
|
|
60
60
|
- repo: https://github.com/stefmolin/docstringify
|
|
61
|
-
rev: 0.
|
|
61
|
+
rev: 0.7.0
|
|
62
62
|
hooks:
|
|
63
63
|
- id: docstringify
|
|
64
64
|
```
|
|
@@ -67,17 +67,17 @@ By default, all docstrings are required. If you want to be more lenient, you can
|
|
|
67
67
|
|
|
68
68
|
```yaml
|
|
69
69
|
- repo: https://github.com/stefmolin/docstringify
|
|
70
|
-
rev: 0.
|
|
70
|
+
rev: 0.7.0
|
|
71
71
|
hooks:
|
|
72
72
|
- id: docstringify
|
|
73
73
|
args: [--threshold=0.75]
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
-
If you would like to see suggested docstring templates (inferred from type annotations for functions and methods), provide the `--suggest-changes` argument, along with the docstring style you want to use (options are `google` and `
|
|
76
|
+
If you would like to see suggested docstring templates (inferred from type annotations for functions and methods), provide the `--suggest-changes` argument, along with the docstring style you want to use (options are `google`, `numpydoc`, and `stub`). Here, we ask for [numpydoc-style docstring](https://numpydoc.readthedocs.io/en/latest/format.html#) suggestions:
|
|
77
77
|
|
|
78
78
|
```yaml
|
|
79
79
|
- repo: https://github.com/stefmolin/docstringify
|
|
80
|
-
rev: 0.
|
|
80
|
+
rev: 0.7.0
|
|
81
81
|
hooks:
|
|
82
82
|
- id: docstringify
|
|
83
83
|
args: [--suggest-changes=numpydoc]
|
|
@@ -87,7 +87,7 @@ Use `--make-changes` to create a copy of each file with docstring templates. Her
|
|
|
87
87
|
|
|
88
88
|
```yaml
|
|
89
89
|
- repo: https://github.com/stefmolin/docstringify
|
|
90
|
-
rev: 0.
|
|
90
|
+
rev: 0.7.0
|
|
91
91
|
hooks:
|
|
92
92
|
- id: docstringify
|
|
93
93
|
args: [--make-changes=google]
|
|
@@ -9,14 +9,28 @@ from typing import TYPE_CHECKING
|
|
|
9
9
|
|
|
10
10
|
from . import __doc__ as pkg_description
|
|
11
11
|
from . import __version__
|
|
12
|
-
from .converters import
|
|
12
|
+
from .converters import (
|
|
13
|
+
GoogleDocstringConverter,
|
|
14
|
+
NumpydocDocstringConverter,
|
|
15
|
+
StubDocstringConverter,
|
|
16
|
+
)
|
|
13
17
|
from .traversal import DocstringTransformer, DocstringVisitor
|
|
14
18
|
|
|
15
19
|
if TYPE_CHECKING:
|
|
16
20
|
from collections.abc import Sequence
|
|
17
21
|
|
|
22
|
+
|
|
18
23
|
PROG = __package__
|
|
19
|
-
STYLES
|
|
24
|
+
STYLES: dict[
|
|
25
|
+
str,
|
|
26
|
+
type[GoogleDocstringConverter]
|
|
27
|
+
| type[NumpydocDocstringConverter]
|
|
28
|
+
| type[StubDocstringConverter],
|
|
29
|
+
] = {
|
|
30
|
+
'google': GoogleDocstringConverter,
|
|
31
|
+
'numpydoc': NumpydocDocstringConverter,
|
|
32
|
+
'stub': StubDocstringConverter,
|
|
33
|
+
}
|
|
20
34
|
CLI_DEFAULTS = {'threshold': 1.0}
|
|
21
35
|
|
|
22
36
|
|
|
@@ -74,22 +88,19 @@ def main(argv: Sequence[str] | None = None) -> int:
|
|
|
74
88
|
)
|
|
75
89
|
args = parser.parse_args(argv)
|
|
76
90
|
|
|
77
|
-
if style := (
|
|
78
|
-
args.make_changes or args.make_changes_inplace or args.suggest_changes
|
|
79
|
-
):
|
|
80
|
-
converter = STYLES[style]
|
|
81
|
-
else:
|
|
82
|
-
converter = None
|
|
83
|
-
|
|
84
91
|
get_docstring_processor = (
|
|
85
92
|
partial(
|
|
86
93
|
DocstringTransformer,
|
|
87
|
-
converter=
|
|
94
|
+
converter=STYLES[style],
|
|
88
95
|
overwrite=bool(args.make_changes_inplace),
|
|
89
96
|
verbose=args.verbose,
|
|
90
97
|
)
|
|
91
|
-
if args.make_changes or args.make_changes_inplace
|
|
92
|
-
else partial(
|
|
98
|
+
if (style := args.make_changes or args.make_changes_inplace)
|
|
99
|
+
else partial(
|
|
100
|
+
DocstringVisitor,
|
|
101
|
+
converter=STYLES.get(args.suggest_changes),
|
|
102
|
+
verbose=args.verbose,
|
|
103
|
+
)
|
|
93
104
|
)
|
|
94
105
|
|
|
95
106
|
docstrings_processed = missing_docstrings = 0
|
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
from .base import DocstringConverter
|
|
4
4
|
from .google import GoogleDocstringConverter
|
|
5
5
|
from .numpydoc import NumpydocDocstringConverter
|
|
6
|
+
from .stub import StubDocstringConverter
|
|
6
7
|
|
|
7
8
|
__all__ = [
|
|
8
9
|
'DocstringConverter',
|
|
9
10
|
'GoogleDocstringConverter',
|
|
10
11
|
'NumpydocDocstringConverter',
|
|
12
|
+
'StubDocstringConverter',
|
|
11
13
|
]
|
|
@@ -8,11 +8,11 @@ from abc import ABC, abstractmethod
|
|
|
8
8
|
from typing import TYPE_CHECKING
|
|
9
9
|
|
|
10
10
|
from ..exceptions import InvalidDocstringError
|
|
11
|
+
from ..nodes.function import FunctionDocstringNode
|
|
11
12
|
|
|
12
13
|
if TYPE_CHECKING:
|
|
13
14
|
from ..components import Parameter
|
|
14
15
|
from ..nodes.base import DocstringNode
|
|
15
|
-
from ..nodes.function import FunctionDocstringNode
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
class DocstringConverter(ABC):
|
|
@@ -238,7 +238,7 @@ class DocstringConverter(ABC):
|
|
|
238
238
|
str | None
|
|
239
239
|
The suggested docstring.
|
|
240
240
|
"""
|
|
241
|
-
if isinstance(docstring_node
|
|
241
|
+
if isinstance(docstring_node, FunctionDocstringNode):
|
|
242
242
|
return (
|
|
243
243
|
self.to_function_docstring(docstring_node, indent=indent)
|
|
244
244
|
if docstring_node.docstring_required
|
|
@@ -81,7 +81,7 @@ class GoogleDocstringConverter(DocstringConverter):
|
|
|
81
81
|
category = f'{f", {parameter.category}" if parameter.category else ""}'
|
|
82
82
|
return (
|
|
83
83
|
f' {parameter.name} ({parameter.type_}{category}): {DESCRIPTION_PLACEHOLDER}'
|
|
84
|
-
f'{f" Defaults to {parameter.default}." if parameter.default
|
|
84
|
+
f'{f" Defaults to {parameter.default}." if parameter.default is not NO_DEFAULT else ""}'
|
|
85
85
|
)
|
|
86
86
|
|
|
87
87
|
def format_return(self, return_type: str | None) -> str:
|
|
@@ -81,7 +81,7 @@ class NumpydocDocstringConverter(DocstringConverter):
|
|
|
81
81
|
return (
|
|
82
82
|
f'{parameter.name} : {parameter.type_}'
|
|
83
83
|
f'{f", {parameter.category}" if parameter.category else ""}'
|
|
84
|
-
f'{f", default={parameter.default}" if parameter.default
|
|
84
|
+
f'{f", default={parameter.default}" if parameter.default is not NO_DEFAULT else ""}'
|
|
85
85
|
f'\n {DESCRIPTION_PLACEHOLDER}'
|
|
86
86
|
)
|
|
87
87
|
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"""Stub docstring converter."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import TYPE_CHECKING
|
|
6
|
+
|
|
7
|
+
from ..components import DESCRIPTION_PLACEHOLDER, Parameter
|
|
8
|
+
from .base import DocstringConverter
|
|
9
|
+
|
|
10
|
+
if TYPE_CHECKING:
|
|
11
|
+
from ..nodes.base import DocstringNode
|
|
12
|
+
from ..nodes.function import FunctionDocstringNode
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class StubDocstringConverter(DocstringConverter):
|
|
16
|
+
"""
|
|
17
|
+
Class defining the DocstringConverter API for injecting ``__description__`` stubs only.
|
|
18
|
+
|
|
19
|
+
Parameters
|
|
20
|
+
----------
|
|
21
|
+
quote : bool
|
|
22
|
+
Whether to surround the generated docstrings in triple quotes.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
def __init__(self, quote: bool) -> None:
|
|
26
|
+
super().__init__(
|
|
27
|
+
parameters_section_template='', returns_section_template='', quote=quote
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
def to_function_docstring(
|
|
31
|
+
self, docstring_node: FunctionDocstringNode, indent: int
|
|
32
|
+
) -> str:
|
|
33
|
+
"""
|
|
34
|
+
Convert an AST node into a function docstring.
|
|
35
|
+
|
|
36
|
+
Parameters
|
|
37
|
+
----------
|
|
38
|
+
docstring_node : FunctionDocstringNode
|
|
39
|
+
An instance of :class:`.FunctionDocstringNode`, which wraps an instance of
|
|
40
|
+
:class:`ast.FunctionDef` or :class:`ast.AsyncFunctionDef`, adding additional
|
|
41
|
+
context relevant for Docstringify.
|
|
42
|
+
indent : int
|
|
43
|
+
The number of spaces by which to indent the docstring.
|
|
44
|
+
|
|
45
|
+
Returns
|
|
46
|
+
-------
|
|
47
|
+
str
|
|
48
|
+
The function docstring.
|
|
49
|
+
"""
|
|
50
|
+
return self.format_docstring(DESCRIPTION_PLACEHOLDER, indent=indent)
|
|
51
|
+
|
|
52
|
+
def format_parameter(self, parameter: Parameter) -> str:
|
|
53
|
+
"""
|
|
54
|
+
Convert a :class:`.Parameter` instance into an entry in the parameters section
|
|
55
|
+
of the docstring.
|
|
56
|
+
|
|
57
|
+
Parameters
|
|
58
|
+
----------
|
|
59
|
+
parameter : Parameter
|
|
60
|
+
Information on the function parameter, including its name, type, and default
|
|
61
|
+
value (if it has one).
|
|
62
|
+
|
|
63
|
+
Returns
|
|
64
|
+
-------
|
|
65
|
+
str
|
|
66
|
+
An empty string.
|
|
67
|
+
"""
|
|
68
|
+
return ''
|
|
69
|
+
|
|
70
|
+
def format_return(self, return_type: str | None) -> str:
|
|
71
|
+
"""
|
|
72
|
+
Convert a return type into an entry in the returns section of the docstring.
|
|
73
|
+
|
|
74
|
+
Parameters
|
|
75
|
+
----------
|
|
76
|
+
return_type : str | None
|
|
77
|
+
The return type name for the function. This will be either a string for the
|
|
78
|
+
name (e.g., ``list[str]``) or ``None``, if ``None`` is returned.
|
|
79
|
+
|
|
80
|
+
Returns
|
|
81
|
+
-------
|
|
82
|
+
str
|
|
83
|
+
An empty string.
|
|
84
|
+
"""
|
|
85
|
+
return ''
|
|
86
|
+
|
|
87
|
+
def to_module_docstring(self, docstring_node: DocstringNode) -> str:
|
|
88
|
+
"""
|
|
89
|
+
Convert an AST node into a module docstring.
|
|
90
|
+
|
|
91
|
+
Parameters
|
|
92
|
+
----------
|
|
93
|
+
docstring_node : DocstringNode
|
|
94
|
+
An instance of :class:`.DocstringNode`, which wraps an instance of
|
|
95
|
+
:class:`ast.Module`, adding additional context relevant for Docstringify.
|
|
96
|
+
|
|
97
|
+
Returns
|
|
98
|
+
-------
|
|
99
|
+
str
|
|
100
|
+
The module docstring.
|
|
101
|
+
"""
|
|
102
|
+
return self.format_docstring(DESCRIPTION_PLACEHOLDER, indent=0)
|
|
103
|
+
|
|
104
|
+
def to_class_docstring(self, docstring_node: DocstringNode, indent: int) -> str:
|
|
105
|
+
"""
|
|
106
|
+
Convert an AST node into a class docstring.
|
|
107
|
+
|
|
108
|
+
Parameters
|
|
109
|
+
----------
|
|
110
|
+
docstring_node : DocstringNode
|
|
111
|
+
An instance of :class:`.DocstringNode`, which wraps an instance of
|
|
112
|
+
:class:`ast.ClassDef`, adding additional context relevant for Docstringify.
|
|
113
|
+
indent : int
|
|
114
|
+
The number of spaces by which to indent the docstring.
|
|
115
|
+
|
|
116
|
+
Returns
|
|
117
|
+
-------
|
|
118
|
+
str
|
|
119
|
+
The class docstring.
|
|
120
|
+
"""
|
|
121
|
+
return self.format_docstring(DESCRIPTION_PLACEHOLDER, indent=indent)
|
|
@@ -40,13 +40,15 @@ class DocstringNode:
|
|
|
40
40
|
) = node
|
|
41
41
|
self.name: str = getattr(node, 'name', self.module_name)
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
self.docstring = docstring if docstring is None else docstring.strip()
|
|
45
|
-
|
|
46
|
-
self.get_source_segment: Callable[[ast.AST], str] = partial(
|
|
43
|
+
self.get_source_segment: Callable[[ast.AST], str | None] = partial(
|
|
47
44
|
ast.get_source_segment, source_code
|
|
48
45
|
)
|
|
49
46
|
|
|
47
|
+
@property
|
|
48
|
+
def docstring(self) -> str | None:
|
|
49
|
+
docstring = ast.get_docstring(self.ast_node)
|
|
50
|
+
return docstring if docstring is None else docstring.strip()
|
|
51
|
+
|
|
50
52
|
@property
|
|
51
53
|
def fully_qualified_name(self) -> str:
|
|
52
54
|
return (
|
|
@@ -69,7 +69,17 @@ class FunctionDocstringNode(DocstringNode):
|
|
|
69
69
|
)
|
|
70
70
|
return NO_DEFAULT
|
|
71
71
|
|
|
72
|
-
def _extract_star_args(self) -> list[Parameter | None
|
|
72
|
+
def _extract_star_args(self) -> list[Parameter | None]:
|
|
73
|
+
"""
|
|
74
|
+
Extract the function's ``*args`` and ``**kwargs`` arguments.
|
|
75
|
+
|
|
76
|
+
Returns
|
|
77
|
+
-------
|
|
78
|
+
list[Parameter | None]
|
|
79
|
+
A list of the form ``[*args, **kwargs]``, where each entry is either a
|
|
80
|
+
:class:`.Parameter` instance, or ``None`` if that type of argument isn't
|
|
81
|
+
part of the function definition.
|
|
82
|
+
"""
|
|
73
83
|
return [
|
|
74
84
|
Parameter(
|
|
75
85
|
name=f'*{arg.arg}' if arg_type == 'vararg' else f'**{arg.arg}',
|
|
@@ -83,7 +93,7 @@ class FunctionDocstringNode(DocstringNode):
|
|
|
83
93
|
for arg in [getattr(self.arguments, arg_type)]
|
|
84
94
|
]
|
|
85
95
|
|
|
86
|
-
def _extract_positional_args(self) -> list[Parameter
|
|
96
|
+
def _extract_positional_args(self) -> list[Parameter]:
|
|
87
97
|
if (default_count := len(positional_defaults := self.arguments.defaults)) < (
|
|
88
98
|
positional_arguments_count := len(self.arguments.posonlyargs)
|
|
89
99
|
+ len(self.arguments.args)
|
|
@@ -110,7 +120,7 @@ class FunctionDocstringNode(DocstringNode):
|
|
|
110
120
|
)
|
|
111
121
|
]
|
|
112
122
|
|
|
113
|
-
def _extract_keyword_args(self) -> list[Parameter
|
|
123
|
+
def _extract_keyword_args(self) -> list[Parameter]:
|
|
114
124
|
return [
|
|
115
125
|
Parameter(
|
|
116
126
|
name=arg.arg,
|
|
@@ -8,7 +8,7 @@ from __future__ import annotations
|
|
|
8
8
|
import ast
|
|
9
9
|
import sys
|
|
10
10
|
from pathlib import Path
|
|
11
|
-
from typing import TYPE_CHECKING
|
|
11
|
+
from typing import TYPE_CHECKING, overload
|
|
12
12
|
|
|
13
13
|
from ..nodes.base import DocstringNode
|
|
14
14
|
from ..nodes.function import FunctionDocstringNode
|
|
@@ -133,6 +133,34 @@ class DocstringVisitor(ast.NodeVisitor):
|
|
|
133
133
|
self.docstrings_inspected += 1
|
|
134
134
|
return docstring_node
|
|
135
135
|
|
|
136
|
+
@overload
|
|
137
|
+
def visit_docstring(
|
|
138
|
+
self,
|
|
139
|
+
node: ast.Module,
|
|
140
|
+
docstring_class: type[DocstringNode],
|
|
141
|
+
) -> ast.Module: ...
|
|
142
|
+
|
|
143
|
+
@overload
|
|
144
|
+
def visit_docstring(
|
|
145
|
+
self,
|
|
146
|
+
node: ast.ClassDef,
|
|
147
|
+
docstring_class: type[DocstringNode],
|
|
148
|
+
) -> ast.ClassDef: ...
|
|
149
|
+
|
|
150
|
+
@overload
|
|
151
|
+
def visit_docstring(
|
|
152
|
+
self,
|
|
153
|
+
node: ast.FunctionDef,
|
|
154
|
+
docstring_class: type[FunctionDocstringNode],
|
|
155
|
+
) -> ast.FunctionDef: ...
|
|
156
|
+
|
|
157
|
+
@overload
|
|
158
|
+
def visit_docstring(
|
|
159
|
+
self,
|
|
160
|
+
node: ast.AsyncFunctionDef,
|
|
161
|
+
docstring_class: type[FunctionDocstringNode],
|
|
162
|
+
) -> ast.AsyncFunctionDef: ...
|
|
163
|
+
|
|
136
164
|
def visit_docstring(
|
|
137
165
|
self,
|
|
138
166
|
node: ast.AsyncFunctionDef | ast.ClassDef | ast.FunctionDef | ast.Module,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: docstringify
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.7.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
|
|
@@ -107,7 +107,7 @@ Add the following to your `.pre-commit-config.yaml` file to block commits with m
|
|
|
107
107
|
|
|
108
108
|
```yaml
|
|
109
109
|
- repo: https://github.com/stefmolin/docstringify
|
|
110
|
-
rev: 0.
|
|
110
|
+
rev: 0.7.0
|
|
111
111
|
hooks:
|
|
112
112
|
- id: docstringify
|
|
113
113
|
```
|
|
@@ -116,17 +116,17 @@ By default, all docstrings are required. If you want to be more lenient, you can
|
|
|
116
116
|
|
|
117
117
|
```yaml
|
|
118
118
|
- repo: https://github.com/stefmolin/docstringify
|
|
119
|
-
rev: 0.
|
|
119
|
+
rev: 0.7.0
|
|
120
120
|
hooks:
|
|
121
121
|
- id: docstringify
|
|
122
122
|
args: [--threshold=0.75]
|
|
123
123
|
```
|
|
124
124
|
|
|
125
|
-
If you would like to see suggested docstring templates (inferred from type annotations for functions and methods), provide the `--suggest-changes` argument, along with the docstring style you want to use (options are `google` and `
|
|
125
|
+
If you would like to see suggested docstring templates (inferred from type annotations for functions and methods), provide the `--suggest-changes` argument, along with the docstring style you want to use (options are `google`, `numpydoc`, and `stub`). Here, we ask for [numpydoc-style docstring](https://numpydoc.readthedocs.io/en/latest/format.html#) suggestions:
|
|
126
126
|
|
|
127
127
|
```yaml
|
|
128
128
|
- repo: https://github.com/stefmolin/docstringify
|
|
129
|
-
rev: 0.
|
|
129
|
+
rev: 0.7.0
|
|
130
130
|
hooks:
|
|
131
131
|
- id: docstringify
|
|
132
132
|
args: [--suggest-changes=numpydoc]
|
|
@@ -136,7 +136,7 @@ Use `--make-changes` to create a copy of each file with docstring templates. Her
|
|
|
136
136
|
|
|
137
137
|
```yaml
|
|
138
138
|
- repo: https://github.com/stefmolin/docstringify
|
|
139
|
-
rev: 0.
|
|
139
|
+
rev: 0.7.0
|
|
140
140
|
hooks:
|
|
141
141
|
- id: docstringify
|
|
142
142
|
args: [--make-changes=google]
|
|
@@ -29,6 +29,7 @@ src/docstringify/converters/__init__.py
|
|
|
29
29
|
src/docstringify/converters/base.py
|
|
30
30
|
src/docstringify/converters/google.py
|
|
31
31
|
src/docstringify/converters/numpydoc.py
|
|
32
|
+
src/docstringify/converters/stub.py
|
|
32
33
|
src/docstringify/nodes/__init__.py
|
|
33
34
|
src/docstringify/nodes/base.py
|
|
34
35
|
src/docstringify/nodes/function.py
|
|
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
|
|
File without changes
|