From 7954b6710dcca0ea43dcb9c0dbd15cc2eef568f5 Mon Sep 17 00:00:00 2001 From: sumansaurabh Date: Mon, 5 Feb 2024 21:33:36 +0530 Subject: [PATCH 1/2] fix the none content --- PyDocSmith/google.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/PyDocSmith/google.py b/PyDocSmith/google.py index 2f8e3e7..fd5bd86 100644 --- a/PyDocSmith/google.py +++ b/PyDocSmith/google.py @@ -109,6 +109,7 @@ def _build_meta(self, text: str, title: str) -> DocstringMeta: return self._build_single_meta(section, text) if ":" not in text: + return raise ParseError(f"Expected a colon in {text!r}.") # Split spec and description @@ -282,7 +283,9 @@ def parse(self, text: str) -> Docstring: c_splits.append((c_matches[-1].end(), len(chunk))) for j, (start, end) in enumerate(c_splits): part = chunk[start:end].strip("\n") - ret.meta.append(self._build_meta(part, title)) + content = self._build_meta(part, title) + if content: + ret.meta.append(content) return ret From 2ca227dae0439f212aadf6a1f90ffd99d702ad0d Mon Sep 17 00:00:00 2001 From: sumansaurabh Date: Tue, 6 Feb 2024 08:49:22 +0530 Subject: [PATCH 2/2] fix the docstring parser for google type whenever content is bad --- PyDocSmith/google.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/PyDocSmith/google.py b/PyDocSmith/google.py index fd5bd86..5076817 100644 --- a/PyDocSmith/google.py +++ b/PyDocSmith/google.py @@ -101,11 +101,15 @@ def _build_meta(self, text: str, title: str) -> DocstringMeta: """ section = self.sections[title] + if text.strip() == "": + return if ( section.type == SectionType.SINGULAR_OR_MULTIPLE and not MULTIPLE_PATTERN.match(text) ) or section.type == SectionType.SINGULAR: + if not text[0].isalnum(): + return return self._build_single_meta(section, text) if ":" not in text: @@ -120,7 +124,12 @@ def _build_meta(self, text: str, title: str) -> DocstringMeta: first_line, rest = desc.split("\n", 1) desc = first_line + "\n" + inspect.cleandoc(rest) desc = desc.strip("\n") - + + if before and not before[0].isalnum(): + return + + if desc and not desc[0].isalnum(): + return return self._build_multi_meta(section, before, desc) @staticmethod @@ -283,10 +292,8 @@ def parse(self, text: str) -> Docstring: c_splits.append((c_matches[-1].end(), len(chunk))) for j, (start, end) in enumerate(c_splits): part = chunk[start:end].strip("\n") - content = self._build_meta(part, title) - if content: - ret.meta.append(content) - + ret.meta.append(self._build_meta(part, title)) + ret.meta = [m for m in ret.meta if m] return ret