From 65890718964d7859c4f8067149edfc3dac184232 Mon Sep 17 00:00:00 2001 From: Stefanie Molin <24376333+stefmolin@users.noreply.github.com> Date: Sat, 12 Jul 2025 20:38:29 -0400 Subject: [PATCH 1/4] Capture start and end lines of empty docstrings in order to exclude them in the file rewrite --- src/docstringify/nodes/base.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/docstringify/nodes/base.py b/src/docstringify/nodes/base.py index 1c28b09..5ad8e76 100644 --- a/src/docstringify/nodes/base.py +++ b/src/docstringify/nodes/base.py @@ -70,6 +70,15 @@ def __init__( ) """Callable to get the source code for the AST node (:attr:`.ast_node`).""" + self.original_docstring_location: tuple[int, int] | None = ( + None + if self.docstring is None + else (self.ast_node.body[0].lineno, self.ast_node.body[0].end_lineno) + ) + """Start and end line of the docstring in the original file, if there was one, + otherwise, ``None``. This is necessary for the rewriting algorithm to exclude + these lines from the file.""" + @property def docstring(self) -> str | None: """ From 3c676e98d58548a170ed6dbfc149c747e3a58065 Mon Sep 17 00:00:00 2001 From: Stefanie Molin <24376333+stefmolin@users.noreply.github.com> Date: Sat, 12 Jul 2025 20:40:09 -0400 Subject: [PATCH 2/4] Account for lines that need to be skipped on file rewrites --- src/docstringify/traversal/transformer.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/docstringify/traversal/transformer.py b/src/docstringify/traversal/transformer.py index 4db47c7..706b3bb 100644 --- a/src/docstringify/traversal/transformer.py +++ b/src/docstringify/traversal/transformer.py @@ -79,6 +79,7 @@ def _convert_to_source_code(self) -> str: source_code = self.source_code.splitlines() output_lines = [] write_line = start_line = 0 + skip_lines = None for missing_docstring in self.missing_docstrings: docstring_node = missing_docstring.ast_node.body[0] @@ -89,6 +90,7 @@ def _convert_to_source_code(self) -> str: if not isinstance(missing_docstring.ast_node, ast.Module): # line before a code node start_line = missing_docstring.ast_node.body[1].lineno - 1 + skip_lines = missing_docstring.original_docstring_location if isinstance(missing_docstring.ast_node, ast.ClassDef): start_line = docstring_node.lineno @@ -109,7 +111,14 @@ def _convert_to_source_code(self) -> str: start_line = missing_docstring.ast_node.body[1].lineno suffix = function_body - output_lines += source_code[write_line:start_line] + if skip_lines: + # need to skip over the empty docstring in the original file + output_lines += ( + source_code[write_line : skip_lines[0] - 1] + + source_code[skip_lines[1] + 1 : start_line] + ) + else: + output_lines += source_code[write_line:start_line] # write docstring if not (docstring := missing_docstring.docstring): From bcbbfbcdeabc7eb81f4a0ce4082899645a89d30c Mon Sep 17 00:00:00 2001 From: Stefanie Molin <24376333+stefmolin@users.noreply.github.com> Date: Sun, 13 Jul 2025 15:20:53 -0400 Subject: [PATCH 3/4] Add badges to README.md --- README.md | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/README.md b/README.md index 90377b8..bfd5b18 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,52 @@ +
+ + # Docstringify Flag missing docstrings and, optionally, generate them from signatures and type annotations. From a8e8411670842336301474679e9ee8e4e58a4488 Mon Sep 17 00:00:00 2001 From: Stefanie Molin <24376333+stefmolin@users.noreply.github.com> Date: Sat, 25 Oct 2025 11:13:14 -0300 Subject: [PATCH 4/4] Clean up README.md formatting Removed unnecessary HTML tags and duplicated title. --- README.md | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 0c0c730..c62c4ed 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -