docstring-generator 2.1.3__tar.gz → 2.2.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.
Files changed (18) hide show
  1. {docstring_generator-2.1.3/src/docstring_generator.egg-info → docstring_generator-2.2.1}/PKG-INFO +86 -3
  2. {docstring_generator-2.1.3 → docstring_generator-2.2.1}/README.md +84 -1
  3. {docstring_generator-2.1.3 → docstring_generator-2.2.1}/pyproject.toml +4 -4
  4. docstring_generator-2.2.1/src/docstring_generator/__init__.py +0 -0
  5. {docstring_generator-2.1.3 → docstring_generator-2.2.1}/src/docstring_generator/new_gen_docs.py +48 -18
  6. {docstring_generator-2.1.3 → docstring_generator-2.2.1/src/docstring_generator.egg-info}/PKG-INFO +86 -3
  7. docstring_generator-2.2.1/src/docstring_generator.egg-info/requires.txt +2 -0
  8. {docstring_generator-2.1.3 → docstring_generator-2.2.1}/tests/test_library.py +286 -0
  9. docstring_generator-2.1.3/src/docstring_generator/__init__.py +0 -6
  10. docstring_generator-2.1.3/src/docstring_generator.egg-info/requires.txt +0 -2
  11. {docstring_generator-2.1.3 → docstring_generator-2.2.1}/LICENSE +0 -0
  12. {docstring_generator-2.1.3 → docstring_generator-2.2.1}/NOTICE +0 -0
  13. {docstring_generator-2.1.3 → docstring_generator-2.2.1}/setup.cfg +0 -0
  14. {docstring_generator-2.1.3 → docstring_generator-2.2.1}/src/docstring_generator/output.py +0 -0
  15. {docstring_generator-2.1.3 → docstring_generator-2.2.1}/src/docstring_generator.egg-info/SOURCES.txt +0 -0
  16. {docstring_generator-2.1.3 → docstring_generator-2.2.1}/src/docstring_generator.egg-info/dependency_links.txt +0 -0
  17. {docstring_generator-2.1.3 → docstring_generator-2.2.1}/src/docstring_generator.egg-info/entry_points.txt +0 -0
  18. {docstring_generator-2.1.3 → docstring_generator-2.2.1}/src/docstring_generator.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: docstring-generator
3
- Version: 2.1.3
3
+ Version: 2.2.1
4
4
  Summary: Auto generate docstring from type-hints.
5
5
  Author: FelixTheC
6
6
  License: Apache-2.0
@@ -16,7 +16,7 @@ Description-Content-Type: text/markdown
16
16
  License-File: LICENSE
17
17
  License-File: NOTICE
18
18
  Requires-Dist: click==8.4.2
19
- Requires-Dist: docstring-generator-ext==2.0.14
19
+ Requires-Dist: docstring-generator-ext==2.1.0
20
20
  Dynamic: license-file
21
21
 
22
22
  [![Python 3.10](https://img.shields.io/badge/python-3-blue.svg)](https://www.python.org/downloads/)
@@ -28,7 +28,6 @@ Dynamic: license-file
28
28
  [![VS Code Extension](https://img.shields.io/badge/VS%20Code-Extension-007ACC?logo=visualstudiocode&logoColor=white)](https://marketplace.visualstudio.com/items?itemName=felixthec.docstring-generator-vscode)
29
29
  [![JetBrains File Watcher](https://img.shields.io/badge/JetBrains-File%20Watcher-000000?logo=jetbrains&logoColor=white)](gendocs_file_watchers.xml)
30
30
 
31
-
32
31
  # docstring_generator
33
32
 
34
33
  > **Stop writing boilerplate docstrings by hand.** `docstring_generator` reads your type hints and generates professional, standards-compliant documentation in seconds — keeping your codebase clean, consistent, and AI-ready.
@@ -37,6 +36,10 @@ Python documentation tooling that automatically generates docstrings for functio
37
36
 
38
37
  ---
39
38
 
39
+ ## Read the docs on [readthedocs](https://docstring-generator.readthedocs.io/en/latest/)
40
+
41
+ ---
42
+
40
43
  [![Buy Me A Coffee](https://img.shields.io/badge/Buy%20Me%20A%20Coffee-Donate-ffdd00?style=for-the-badge&logo=buy-me-a-coffee&logoColor=black)](https://www.buymeacoffee.com/FEisenmenger)
41
44
 
42
45
  ## Why docstring_generator?
@@ -193,6 +196,40 @@ gendocs_new mydir/ --style google --overwrite-style true
193
196
 
194
197
  Useful when migrating a codebase from one docstring convention to another.
195
198
 
199
+ ### `--ignore-private` — Skip private functions/methods
200
+
201
+ Skip functions and methods whose name starts with a single underscore (e.g. `_helper`), leaving them untouched. Dunder methods (e.g. `__init__`, `__str__`) are **not** affected by this flag — use `--ignore-magic` for those:
202
+
203
+ ```shell
204
+ gendocs_new mydir/ --ignore-private
205
+ ```
206
+
207
+ Can also be enabled permanently via `pyproject.toml`:
208
+
209
+ ```toml
210
+ [tool.docstring_generator]
211
+ ignore_private = true
212
+ ```
213
+
214
+ **Default:** `False`
215
+
216
+ ### `--ignore-uncommented` — Skip functions without an existing docstring
217
+
218
+ Skip functions and methods that currently have **no docstring at all**, leaving them untouched instead of generating one. Good for simple helper functions where the name is already self-explanatory. Functions that already have *some* docstring are still processed normally (e.g. missing `Parameters`/`Returns` sections are added):
219
+
220
+ ```shell
221
+ gendocs_new mydir/ --ignore-uncommented
222
+ ```
223
+
224
+ Can also be enabled permanently via `pyproject.toml`:
225
+
226
+ ```toml
227
+ [tool.docstring_generator]
228
+ ignore_uncommented = true
229
+ ```
230
+
231
+ **Default:** `False`
232
+
196
233
  ---
197
234
 
198
235
  ## Configuration via `pyproject.toml`
@@ -206,12 +243,58 @@ threshold = 90
206
243
  exclude_files = ["conftest.py", "settings.py"]
207
244
  exclude_dirs = ["tests", "migrations"]
208
245
  ignore_magic = true
246
+ ignore_private = true
247
+ ignore_uncommented = true
209
248
  ```
210
249
 
211
250
  CLI flags always override `pyproject.toml` values. The tool automatically walks up from the target path to find the nearest `pyproject.toml`.
212
251
 
213
252
  ---
214
253
 
254
+ ## Skip Directives — `# docstring: skip` / `# docstring: off` / `# docstring: on`
255
+
256
+ When a CLI flag is too coarse, tell the generator to leave specific parts of a file untouched using `# docstring: skip` comments. Three scopes are supported:
257
+
258
+ ### 1. File-level skip
259
+
260
+ Place the directive within the first 10 lines of the file to skip the entire file:
261
+
262
+ ```python
263
+ # docstring: skip
264
+
265
+ def some_function():
266
+ return None
267
+ ```
268
+
269
+ ### 2. Single-target skip
270
+
271
+ Place the directive as the first statement inside a function or method body to skip just that target:
272
+
273
+ ```python
274
+ def helper_three(a: int) -> int:
275
+ # docstring: skip
276
+ return a
277
+ ```
278
+
279
+ ### 3. Block/Range skip
280
+
281
+ Wrap a group of functions or classes between `# docstring: off` and `# docstring: on` to skip everything in between:
282
+
283
+ ```python
284
+ # docstring: off
285
+ def helper_one():
286
+ ...
287
+
288
+
289
+ def helper_two():
290
+ ...
291
+ # docstring: on
292
+ ```
293
+
294
+ > ⚠️ **Known limitation:** currently only the function immediately following `# docstring: off` is reliably skipped — functions further down the block may still receive a generated docstring. Until this is fixed upstream, prefer the single-target directive on each function if you need every function in a range excluded. See the full [Skip Directives guide](https://felixthec.github.io/docstring_generator/skip-directives/) for details.
295
+
296
+ ---
297
+
215
298
  ## Preserve Custom Descriptions with `$<num>` Placeholders
216
299
 
217
300
  Write your domain-specific notes once — `docstring_generator` will place them in the right parameter slot automatically.
@@ -7,7 +7,6 @@
7
7
  [![VS Code Extension](https://img.shields.io/badge/VS%20Code-Extension-007ACC?logo=visualstudiocode&logoColor=white)](https://marketplace.visualstudio.com/items?itemName=felixthec.docstring-generator-vscode)
8
8
  [![JetBrains File Watcher](https://img.shields.io/badge/JetBrains-File%20Watcher-000000?logo=jetbrains&logoColor=white)](gendocs_file_watchers.xml)
9
9
 
10
-
11
10
  # docstring_generator
12
11
 
13
12
  > **Stop writing boilerplate docstrings by hand.** `docstring_generator` reads your type hints and generates professional, standards-compliant documentation in seconds — keeping your codebase clean, consistent, and AI-ready.
@@ -16,6 +15,10 @@ Python documentation tooling that automatically generates docstrings for functio
16
15
 
17
16
  ---
18
17
 
18
+ ## Read the docs on [readthedocs](https://docstring-generator.readthedocs.io/en/latest/)
19
+
20
+ ---
21
+
19
22
  [![Buy Me A Coffee](https://img.shields.io/badge/Buy%20Me%20A%20Coffee-Donate-ffdd00?style=for-the-badge&logo=buy-me-a-coffee&logoColor=black)](https://www.buymeacoffee.com/FEisenmenger)
20
23
 
21
24
  ## Why docstring_generator?
@@ -172,6 +175,40 @@ gendocs_new mydir/ --style google --overwrite-style true
172
175
 
173
176
  Useful when migrating a codebase from one docstring convention to another.
174
177
 
178
+ ### `--ignore-private` — Skip private functions/methods
179
+
180
+ Skip functions and methods whose name starts with a single underscore (e.g. `_helper`), leaving them untouched. Dunder methods (e.g. `__init__`, `__str__`) are **not** affected by this flag — use `--ignore-magic` for those:
181
+
182
+ ```shell
183
+ gendocs_new mydir/ --ignore-private
184
+ ```
185
+
186
+ Can also be enabled permanently via `pyproject.toml`:
187
+
188
+ ```toml
189
+ [tool.docstring_generator]
190
+ ignore_private = true
191
+ ```
192
+
193
+ **Default:** `False`
194
+
195
+ ### `--ignore-uncommented` — Skip functions without an existing docstring
196
+
197
+ Skip functions and methods that currently have **no docstring at all**, leaving them untouched instead of generating one. Good for simple helper functions where the name is already self-explanatory. Functions that already have *some* docstring are still processed normally (e.g. missing `Parameters`/`Returns` sections are added):
198
+
199
+ ```shell
200
+ gendocs_new mydir/ --ignore-uncommented
201
+ ```
202
+
203
+ Can also be enabled permanently via `pyproject.toml`:
204
+
205
+ ```toml
206
+ [tool.docstring_generator]
207
+ ignore_uncommented = true
208
+ ```
209
+
210
+ **Default:** `False`
211
+
175
212
  ---
176
213
 
177
214
  ## Configuration via `pyproject.toml`
@@ -185,12 +222,58 @@ threshold = 90
185
222
  exclude_files = ["conftest.py", "settings.py"]
186
223
  exclude_dirs = ["tests", "migrations"]
187
224
  ignore_magic = true
225
+ ignore_private = true
226
+ ignore_uncommented = true
188
227
  ```
189
228
 
190
229
  CLI flags always override `pyproject.toml` values. The tool automatically walks up from the target path to find the nearest `pyproject.toml`.
191
230
 
192
231
  ---
193
232
 
233
+ ## Skip Directives — `# docstring: skip` / `# docstring: off` / `# docstring: on`
234
+
235
+ When a CLI flag is too coarse, tell the generator to leave specific parts of a file untouched using `# docstring: skip` comments. Three scopes are supported:
236
+
237
+ ### 1. File-level skip
238
+
239
+ Place the directive within the first 10 lines of the file to skip the entire file:
240
+
241
+ ```python
242
+ # docstring: skip
243
+
244
+ def some_function():
245
+ return None
246
+ ```
247
+
248
+ ### 2. Single-target skip
249
+
250
+ Place the directive as the first statement inside a function or method body to skip just that target:
251
+
252
+ ```python
253
+ def helper_three(a: int) -> int:
254
+ # docstring: skip
255
+ return a
256
+ ```
257
+
258
+ ### 3. Block/Range skip
259
+
260
+ Wrap a group of functions or classes between `# docstring: off` and `# docstring: on` to skip everything in between:
261
+
262
+ ```python
263
+ # docstring: off
264
+ def helper_one():
265
+ ...
266
+
267
+
268
+ def helper_two():
269
+ ...
270
+ # docstring: on
271
+ ```
272
+
273
+ > ⚠️ **Known limitation:** currently only the function immediately following `# docstring: off` is reliably skipped — functions further down the block may still receive a generated docstring. Until this is fixed upstream, prefer the single-target directive on each function if you need every function in a range excluded. See the full [Skip Directives guide](https://felixthec.github.io/docstring_generator/skip-directives/) for details.
274
+
275
+ ---
276
+
194
277
  ## Preserve Custom Descriptions with `$<num>` Placeholders
195
278
 
196
279
  Write your domain-specific notes once — `docstring_generator` will place them in the right parameter slot automatically.
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "docstring-generator"
3
- version = "2.1.3"
3
+ version = "2.2.1"
4
4
  description = "Auto generate docstring from type-hints."
5
5
  authors = [
6
6
  { name = "FelixTheC" },
@@ -22,16 +22,16 @@ classifiers=[
22
22
 
23
23
  dependencies = [
24
24
  "click == 8.4.2",
25
- "docstring-generator-ext==2.0.14",
25
+ "docstring-generator-ext==2.1.0",
26
26
  ]
27
27
 
28
28
  [dependency-groups]
29
29
  dev = [
30
30
  "pytest>=9.1.1",
31
31
  "pytest-cov>=7.1.0",
32
- "ruff==0.15.21",
32
+ "ruff==0.16.5",
33
33
  "fastapi==0.141.1",
34
- "sqlalchemy==2.0.51"
34
+ "sqlalchemy==2.0.52"
35
35
  ]
36
36
 
37
37
  [tool.uv]
@@ -3,10 +3,10 @@ import pathlib
3
3
  import shutil
4
4
  import subprocess
5
5
  import tempfile
6
+ import tomllib # type: ignore
6
7
 
7
8
  import click
8
9
  import docstring_generator_ext
9
- import tomllib # type: ignore
10
10
 
11
11
  from docstring_generator.output import print_results
12
12
 
@@ -24,7 +24,7 @@ def find_pyproject_toml(start_paths: tuple[str, ...]) -> pathlib.Path | None:
24
24
 
25
25
  Parameters
26
26
  ----------
27
- start_paths : tuple[str, Ellipsis] [Argument]
27
+ start_paths : tuple[str, Ellipsis]
28
28
 
29
29
  Returns
30
30
  -------
@@ -50,7 +50,7 @@ def load_toml_config(config_path: pathlib.Path | None) -> dict:
50
50
  """Finds and parses configuration options from pyproject.toml.
51
51
  Parameters
52
52
  ----------
53
- config_path : Union[pathlib.Path, None] [Argument]
53
+ config_path : Union[pathlib.Path, None]
54
54
 
55
55
  Returns
56
56
  -------
@@ -98,6 +98,16 @@ def load_toml_config(config_path: pathlib.Path | None) -> dict:
98
98
  is_flag=True,
99
99
  help="Only process files changed or staged in git. Aborts if git is not available.",
100
100
  )
101
+ @click.option(
102
+ "--ignore-private",
103
+ is_flag=True,
104
+ help="Ignore private functions.",
105
+ )
106
+ @click.option(
107
+ "--ignore-uncommented",
108
+ is_flag=True,
109
+ help="Ignore functions without docstrings. This is good for simple helper functions where the name is enough",
110
+ )
101
111
  def main(
102
112
  paths: tuple[str, ...],
103
113
  style: str,
@@ -110,21 +120,25 @@ def main(
110
120
  dry_run: bool,
111
121
  ignore_magic: bool,
112
122
  changed_only: bool,
123
+ ignore_private: bool,
124
+ ignore_uncommented: bool,
113
125
  ) -> None:
114
126
  """
115
127
  Parameters
116
128
  ----------
117
- paths : tuple[str, Ellipsis] [Argument]
118
- style : str [Argument]
119
- check : bool [Argument]
120
- strict : bool [Argument]
121
- threshold : Union[int, None] [Argument]
122
- exclude_file : list[str] [Argument]
123
- exclude_dir : list[str] [Argument]
124
- overwrite_style : bool [Argument]
125
- dry_run : bool [Argument]
126
- ignore_magic : bool [Argument]
127
- changed_only : bool [Argument]
129
+ paths : tuple[str, Ellipsis]
130
+ style : str
131
+ check : bool
132
+ strict : bool
133
+ threshold : Union[int, None]
134
+ exclude_file : list[str]
135
+ exclude_dir : list[str]
136
+ overwrite_style : bool
137
+ dry_run : bool
138
+ ignore_magic : bool
139
+ changed_only : bool
140
+ ignore_private : bool
141
+ ignore_uncommented : bool
128
142
 
129
143
  Returns
130
144
  -------
@@ -138,6 +152,8 @@ def main(
138
152
  _exclude_files = config.get("exclude_files", [])
139
153
  _exclude_dirs = config.get("exclude_dirs", [])
140
154
  _ignore_magic = config.get("ignore_magic", False)
155
+ _ignore_private = config.get("ignore_private", False)
156
+ _ignore_uncommented = config.get("ignore_uncommented", False)
141
157
 
142
158
  # CLI args always wins
143
159
  if exclude_file:
@@ -146,6 +162,10 @@ def main(
146
162
  _exclude_dirs = exclude_dir
147
163
  if ignore_magic:
148
164
  _ignore_magic = ignore_magic
165
+ if ignore_private:
166
+ _ignore_private = ignore_private
167
+ if ignore_uncommented:
168
+ _ignore_uncommented = ignore_uncommented
149
169
 
150
170
  changed_files: set[str] | None = None
151
171
  if changed_only:
@@ -202,7 +222,7 @@ def main(
202
222
  if check:
203
223
  checked_files = {
204
224
  file.absolute().as_posix(): docstring_generator_ext.check_docstring(
205
- file.absolute().as_posix(), _ignore_magic
225
+ file.absolute().as_posix(), _ignore_magic, _ignore_private, _ignore_uncommented
206
226
  )
207
227
  for file in files_
208
228
  }
@@ -223,7 +243,12 @@ def main(
223
243
  shutil.copy2(file, tmp_path)
224
244
  try:
225
245
  docstring_generator_ext.parse_file(
226
- tmp_path.as_posix(), docstring_style, overwrite_style
246
+ tmp_path.as_posix(),
247
+ docstring_style,
248
+ overwrite_style,
249
+ _ignore_magic,
250
+ _ignore_private,
251
+ _ignore_uncommented,
227
252
  )
228
253
  original = file.read_text(encoding="utf-8").splitlines(keepends=True)
229
254
  modified = tmp_path.read_text(encoding="utf-8").splitlines(keepends=True)
@@ -243,11 +268,16 @@ def main(
243
268
  tmp_path.unlink(missing_ok=True)
244
269
  else:
245
270
  docstring_generator_ext.parse_file(
246
- file.absolute().as_posix(), docstring_style, overwrite_style
271
+ file.absolute().as_posix(),
272
+ docstring_style,
273
+ overwrite_style,
274
+ _ignore_magic,
275
+ _ignore_private,
276
+ _ignore_uncommented,
247
277
  )
248
278
  except SyntaxError as e:
249
279
  print(f"Error processing file {file}: {e}")
250
- except Exception as e:
280
+ except Exception as e: # noqa
251
281
  print(f"Error processing file {file}: {e}")
252
282
 
253
283
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: docstring-generator
3
- Version: 2.1.3
3
+ Version: 2.2.1
4
4
  Summary: Auto generate docstring from type-hints.
5
5
  Author: FelixTheC
6
6
  License: Apache-2.0
@@ -16,7 +16,7 @@ Description-Content-Type: text/markdown
16
16
  License-File: LICENSE
17
17
  License-File: NOTICE
18
18
  Requires-Dist: click==8.4.2
19
- Requires-Dist: docstring-generator-ext==2.0.14
19
+ Requires-Dist: docstring-generator-ext==2.1.0
20
20
  Dynamic: license-file
21
21
 
22
22
  [![Python 3.10](https://img.shields.io/badge/python-3-blue.svg)](https://www.python.org/downloads/)
@@ -28,7 +28,6 @@ Dynamic: license-file
28
28
  [![VS Code Extension](https://img.shields.io/badge/VS%20Code-Extension-007ACC?logo=visualstudiocode&logoColor=white)](https://marketplace.visualstudio.com/items?itemName=felixthec.docstring-generator-vscode)
29
29
  [![JetBrains File Watcher](https://img.shields.io/badge/JetBrains-File%20Watcher-000000?logo=jetbrains&logoColor=white)](gendocs_file_watchers.xml)
30
30
 
31
-
32
31
  # docstring_generator
33
32
 
34
33
  > **Stop writing boilerplate docstrings by hand.** `docstring_generator` reads your type hints and generates professional, standards-compliant documentation in seconds — keeping your codebase clean, consistent, and AI-ready.
@@ -37,6 +36,10 @@ Python documentation tooling that automatically generates docstrings for functio
37
36
 
38
37
  ---
39
38
 
39
+ ## Read the docs on [readthedocs](https://docstring-generator.readthedocs.io/en/latest/)
40
+
41
+ ---
42
+
40
43
  [![Buy Me A Coffee](https://img.shields.io/badge/Buy%20Me%20A%20Coffee-Donate-ffdd00?style=for-the-badge&logo=buy-me-a-coffee&logoColor=black)](https://www.buymeacoffee.com/FEisenmenger)
41
44
 
42
45
  ## Why docstring_generator?
@@ -193,6 +196,40 @@ gendocs_new mydir/ --style google --overwrite-style true
193
196
 
194
197
  Useful when migrating a codebase from one docstring convention to another.
195
198
 
199
+ ### `--ignore-private` — Skip private functions/methods
200
+
201
+ Skip functions and methods whose name starts with a single underscore (e.g. `_helper`), leaving them untouched. Dunder methods (e.g. `__init__`, `__str__`) are **not** affected by this flag — use `--ignore-magic` for those:
202
+
203
+ ```shell
204
+ gendocs_new mydir/ --ignore-private
205
+ ```
206
+
207
+ Can also be enabled permanently via `pyproject.toml`:
208
+
209
+ ```toml
210
+ [tool.docstring_generator]
211
+ ignore_private = true
212
+ ```
213
+
214
+ **Default:** `False`
215
+
216
+ ### `--ignore-uncommented` — Skip functions without an existing docstring
217
+
218
+ Skip functions and methods that currently have **no docstring at all**, leaving them untouched instead of generating one. Good for simple helper functions where the name is already self-explanatory. Functions that already have *some* docstring are still processed normally (e.g. missing `Parameters`/`Returns` sections are added):
219
+
220
+ ```shell
221
+ gendocs_new mydir/ --ignore-uncommented
222
+ ```
223
+
224
+ Can also be enabled permanently via `pyproject.toml`:
225
+
226
+ ```toml
227
+ [tool.docstring_generator]
228
+ ignore_uncommented = true
229
+ ```
230
+
231
+ **Default:** `False`
232
+
196
233
  ---
197
234
 
198
235
  ## Configuration via `pyproject.toml`
@@ -206,12 +243,58 @@ threshold = 90
206
243
  exclude_files = ["conftest.py", "settings.py"]
207
244
  exclude_dirs = ["tests", "migrations"]
208
245
  ignore_magic = true
246
+ ignore_private = true
247
+ ignore_uncommented = true
209
248
  ```
210
249
 
211
250
  CLI flags always override `pyproject.toml` values. The tool automatically walks up from the target path to find the nearest `pyproject.toml`.
212
251
 
213
252
  ---
214
253
 
254
+ ## Skip Directives — `# docstring: skip` / `# docstring: off` / `# docstring: on`
255
+
256
+ When a CLI flag is too coarse, tell the generator to leave specific parts of a file untouched using `# docstring: skip` comments. Three scopes are supported:
257
+
258
+ ### 1. File-level skip
259
+
260
+ Place the directive within the first 10 lines of the file to skip the entire file:
261
+
262
+ ```python
263
+ # docstring: skip
264
+
265
+ def some_function():
266
+ return None
267
+ ```
268
+
269
+ ### 2. Single-target skip
270
+
271
+ Place the directive as the first statement inside a function or method body to skip just that target:
272
+
273
+ ```python
274
+ def helper_three(a: int) -> int:
275
+ # docstring: skip
276
+ return a
277
+ ```
278
+
279
+ ### 3. Block/Range skip
280
+
281
+ Wrap a group of functions or classes between `# docstring: off` and `# docstring: on` to skip everything in between:
282
+
283
+ ```python
284
+ # docstring: off
285
+ def helper_one():
286
+ ...
287
+
288
+
289
+ def helper_two():
290
+ ...
291
+ # docstring: on
292
+ ```
293
+
294
+ > ⚠️ **Known limitation:** currently only the function immediately following `# docstring: off` is reliably skipped — functions further down the block may still receive a generated docstring. Until this is fixed upstream, prefer the single-target directive on each function if you need every function in a range excluded. See the full [Skip Directives guide](https://felixthec.github.io/docstring_generator/skip-directives/) for details.
295
+
296
+ ---
297
+
215
298
  ## Preserve Custom Descriptions with `$<num>` Placeholders
216
299
 
217
300
  Write your domain-specific notes once — `docstring_generator` will place them in the right parameter slot automatically.
@@ -0,0 +1,2 @@
1
+ click==8.4.2
2
+ docstring-generator-ext==2.1.0
@@ -330,6 +330,292 @@ def test_changed_only_combined_with_dry_run():
330
330
  )
331
331
 
332
332
 
333
+ # ---------------------------------------------------------------------------
334
+ # --ignore-private tests
335
+ # ---------------------------------------------------------------------------
336
+
337
+ def test_ignore_private_skips_private_functions():
338
+ gendocs_new = Path(sys.executable).parent / "gendocs_new"
339
+
340
+ with NamedTemporaryFile(suffix=".py", delete=False, mode="w") as tmp_file:
341
+ tmp_path = Path(tmp_file.name)
342
+ tmp_file.write(
343
+ "def public_func(a: int) -> int:\n"
344
+ " return a\n"
345
+ "\n"
346
+ "def _private_func(a: int) -> int:\n"
347
+ " return a\n"
348
+ )
349
+
350
+ try:
351
+ result = subprocess.run(
352
+ [str(gendocs_new), "--ignore-private", str(tmp_path)],
353
+ capture_output=True,
354
+ text=True,
355
+ )
356
+ assert result.returncode == 0, f"gendocs_new failed:\n{result.stderr}"
357
+
358
+ content = tmp_path.read_text(encoding="utf-8")
359
+ assert '"""' in content.split("def _private_func")[0], (
360
+ "public function should have received a docstring"
361
+ )
362
+ assert '"""' not in content.split("def _private_func")[1], (
363
+ "--ignore-private should leave private functions untouched"
364
+ )
365
+ finally:
366
+ tmp_path.unlink(missing_ok=True)
367
+
368
+
369
+ def test_ignore_private_does_not_skip_dunder_methods():
370
+ gendocs_new = Path(sys.executable).parent / "gendocs_new"
371
+
372
+ with NamedTemporaryFile(suffix=".py", delete=False, mode="w") as tmp_file:
373
+ tmp_path = Path(tmp_file.name)
374
+ tmp_file.write(
375
+ "class Foo:\n"
376
+ " def __init__(self, a: int) -> None:\n"
377
+ " self.a = a\n"
378
+ )
379
+
380
+ try:
381
+ result = subprocess.run(
382
+ [str(gendocs_new), "--ignore-private", str(tmp_path)],
383
+ capture_output=True,
384
+ text=True,
385
+ )
386
+ assert result.returncode == 0, f"gendocs_new failed:\n{result.stderr}"
387
+
388
+ content = tmp_path.read_text(encoding="utf-8")
389
+ assert '"""' in content, (
390
+ "--ignore-private should not skip dunder methods like __init__"
391
+ )
392
+ finally:
393
+ tmp_path.unlink(missing_ok=True)
394
+
395
+
396
+ def test_ignore_private_via_pyproject_config():
397
+ with TemporaryDirectory() as tmp_dir:
398
+ tmp_dir_path = Path(tmp_dir)
399
+
400
+ (tmp_dir_path / "pyproject.toml").write_text(
401
+ "[tool.docstring_generator]\nignore_private = true\n",
402
+ encoding="utf-8",
403
+ )
404
+ sample = tmp_dir_path / "sample.py"
405
+ sample.write_text(
406
+ "def public_func(a: int) -> int:\n"
407
+ " return a\n"
408
+ "\n"
409
+ "def _private_func(a: int) -> int:\n"
410
+ " return a\n",
411
+ encoding="utf-8",
412
+ )
413
+
414
+ gendocs_new = Path(sys.executable).parent / "gendocs_new"
415
+ result = subprocess.run(
416
+ [str(gendocs_new), str(sample)],
417
+ capture_output=True,
418
+ text=True,
419
+ cwd=tmp_dir,
420
+ )
421
+ assert result.returncode == 0, f"gendocs_new failed:\n{result.stderr}"
422
+
423
+ content = sample.read_text(encoding="utf-8")
424
+ assert '"""' in content.split("def _private_func")[0]
425
+ assert '"""' not in content.split("def _private_func")[1]
426
+
427
+
428
+ # ---------------------------------------------------------------------------
429
+ # --ignore-uncommented tests
430
+ # ---------------------------------------------------------------------------
431
+
432
+ def test_ignore_uncommented_skips_functions_without_docstring():
433
+ gendocs_new = Path(sys.executable).parent / "gendocs_new"
434
+
435
+ with NamedTemporaryFile(suffix=".py", delete=False, mode="w") as tmp_file:
436
+ tmp_path = Path(tmp_file.name)
437
+ tmp_file.write(
438
+ "def has_docstring(a: int) -> int:\n"
439
+ ' """Existing docstring."""\n'
440
+ " return a\n"
441
+ "\n"
442
+ "def no_docstring(a: int) -> int:\n"
443
+ " return a\n"
444
+ )
445
+
446
+ try:
447
+ result = subprocess.run(
448
+ [str(gendocs_new), "--ignore-uncommented", str(tmp_path)],
449
+ capture_output=True,
450
+ text=True,
451
+ )
452
+ assert result.returncode == 0, f"gendocs_new failed:\n{result.stderr}"
453
+
454
+ content = tmp_path.read_text(encoding="utf-8")
455
+ has_docstring_part, no_docstring_part = content.split("def no_docstring")
456
+
457
+ # the already-documented function should have been extended with parameter info
458
+ assert "Parameters" in has_docstring_part, (
459
+ "functions that already have a docstring must still be processed"
460
+ )
461
+ # the fully undocumented function must be left untouched
462
+ assert '"""' not in no_docstring_part, (
463
+ "--ignore-uncommented should leave functions without a docstring untouched"
464
+ )
465
+ finally:
466
+ tmp_path.unlink(missing_ok=True)
467
+
468
+
469
+ def test_ignore_uncommented_via_pyproject_config():
470
+ with TemporaryDirectory() as tmp_dir:
471
+ tmp_dir_path = Path(tmp_dir)
472
+
473
+ (tmp_dir_path / "pyproject.toml").write_text(
474
+ "[tool.docstring_generator]\nignore_uncommented = true\n",
475
+ encoding="utf-8",
476
+ )
477
+ sample = tmp_dir_path / "sample.py"
478
+ sample.write_text(
479
+ "def no_docstring(a: int) -> int:\n"
480
+ " return a\n",
481
+ encoding="utf-8",
482
+ )
483
+
484
+ gendocs_new = Path(sys.executable).parent / "gendocs_new"
485
+ result = subprocess.run(
486
+ [str(gendocs_new), str(sample)],
487
+ capture_output=True,
488
+ text=True,
489
+ cwd=tmp_dir,
490
+ )
491
+ assert result.returncode == 0, f"gendocs_new failed:\n{result.stderr}"
492
+
493
+ content = sample.read_text(encoding="utf-8")
494
+ assert '"""' not in content, (
495
+ "--ignore-uncommented (via pyproject.toml) should leave undocumented functions untouched"
496
+ )
497
+
498
+
499
+ # ---------------------------------------------------------------------------
500
+ # `# docstring: skip` / `# docstring: off` / `# docstring: on` directive tests
501
+ # ---------------------------------------------------------------------------
502
+
503
+ def test_skip_directive_file_level_leaves_file_untouched():
504
+ gendocs_new = Path(sys.executable).parent / "gendocs_new"
505
+
506
+ with NamedTemporaryFile(suffix=".py", delete=False, mode="w") as tmp_file:
507
+ tmp_path = Path(tmp_file.name)
508
+ tmp_file.write(
509
+ "# docstring: skip\n"
510
+ "\n"
511
+ "def some_function(a: int) -> int:\n"
512
+ " return a\n"
513
+ )
514
+
515
+ try:
516
+ original_content = tmp_path.read_text(encoding="utf-8")
517
+
518
+ result = subprocess.run(
519
+ [str(gendocs_new), str(tmp_path)],
520
+ capture_output=True,
521
+ text=True,
522
+ )
523
+ assert result.returncode == 0, f"gendocs_new failed:\n{result.stderr}"
524
+
525
+ assert tmp_path.read_text(encoding="utf-8") == original_content, (
526
+ "a `# docstring: skip` comment within the first 10 lines must skip the whole file"
527
+ )
528
+ finally:
529
+ tmp_path.unlink(missing_ok=True)
530
+
531
+
532
+ def test_skip_directive_single_target_skips_only_that_function():
533
+ gendocs_new = Path(sys.executable).parent / "gendocs_new"
534
+
535
+ padding = "".join(f"# padding line {i}\n" for i in range(1, 11))
536
+ source = (
537
+ padding
538
+ + "def helper_three(a: int) -> int:\n"
539
+ + " # docstring: skip\n"
540
+ + " return a\n"
541
+ + "\n"
542
+ + "def normal_func(a: int) -> int:\n"
543
+ + " return a\n"
544
+ )
545
+
546
+ with NamedTemporaryFile(suffix=".py", delete=False, mode="w") as tmp_file:
547
+ tmp_path = Path(tmp_file.name)
548
+ tmp_file.write(source)
549
+
550
+ try:
551
+ result = subprocess.run(
552
+ [str(gendocs_new), str(tmp_path)],
553
+ capture_output=True,
554
+ text=True,
555
+ )
556
+ assert result.returncode == 0, f"gendocs_new failed:\n{result.stderr}"
557
+
558
+ content = tmp_path.read_text(encoding="utf-8")
559
+ helper_part, normal_part = content.split("def normal_func")
560
+
561
+ assert '"""' not in helper_part, (
562
+ "a `# docstring: skip` placed below a function must skip just that function"
563
+ )
564
+ assert '"""' in normal_part, (
565
+ "functions without the skip directive must still be processed"
566
+ )
567
+ finally:
568
+ tmp_path.unlink(missing_ok=True)
569
+
570
+
571
+ @pytest.mark.xfail(reason="Block skip via `# docstring: off` / `# docstring: on` is not honored by the extension")
572
+ def test_skip_directive_block_range_skips_everything_between():
573
+ gendocs_new = Path(sys.executable).parent / "gendocs_new"
574
+
575
+ padding = "".join(f"# padding line {i}\n" for i in range(1, 11))
576
+ source = (
577
+ padding
578
+ + "def before_block(a: int) -> int:\n"
579
+ + " return a\n"
580
+ + "\n"
581
+ + "# docstring: off\n"
582
+ + "def helper_one(a: int) -> int:\n"
583
+ + " return a\n"
584
+ + "\n"
585
+ + "\n"
586
+ + "def helper_two(a: int) -> int:\n"
587
+ + " return a\n"
588
+ + "# docstring: on\n"
589
+ + "\n"
590
+ + "def after_block(a: int) -> int:\n"
591
+ + " return a\n"
592
+ )
593
+
594
+ with NamedTemporaryFile(suffix=".py", delete=False, mode="w") as tmp_file:
595
+ tmp_path = Path(tmp_file.name)
596
+ tmp_file.write(source)
597
+
598
+ try:
599
+ result = subprocess.run(
600
+ [str(gendocs_new), str(tmp_path)],
601
+ capture_output=True,
602
+ text=True,
603
+ )
604
+ assert result.returncode == 0, f"gendocs_new failed:\n{result.stderr}"
605
+
606
+ content = tmp_path.read_text(encoding="utf-8")
607
+ before, rest = content.split("def helper_one")
608
+ block, after = rest.split("# docstring: on")
609
+
610
+ assert '"""' in before, "functions before the block must still be processed"
611
+ assert '"""' not in block, (
612
+ "functions between `# docstring: off` and `# docstring: on` must be skipped"
613
+ )
614
+ assert '"""' in after, "functions after the block must still be processed"
615
+ finally:
616
+ tmp_path.unlink(missing_ok=True)
617
+
618
+
333
619
  @pytest.mark.xfail
334
620
  def test_overwrite_existing_style():
335
621
  gendocs_new = Path(sys.executable).parent / "gendocs_new"
@@ -1,6 +0,0 @@
1
- #!/usr/bin/env python3
2
- # -*- coding: utf-8 -*-
3
- """
4
- @created: 01.08.21
5
- @author: felix
6
- """
@@ -1,2 +0,0 @@
1
- click==8.4.2
2
- docstring-generator-ext==2.0.14