From 6a3463cc03427c109c9a198a0891c2b621fca448 Mon Sep 17 00:00:00 2001 From: Omar Al-Jarrah Date: Sat, 1 Jul 2023 02:46:44 +0300 Subject: [PATCH 1/4] chore(common): expose yields as a property. --- docstring_parser/common.py | 11 +++ docstring_parser/tests/test_google.py | 107 ++++++++++++++++++++++++++ 2 files changed, 118 insertions(+) diff --git a/docstring_parser/common.py b/docstring_parser/common.py index e3e5a56..9dcbf3c 100644 --- a/docstring_parser/common.py +++ b/docstring_parser/common.py @@ -193,6 +193,17 @@ def many_returns(self) -> T.List[DocstringReturns]: item for item in self.meta if isinstance(item, DocstringReturns) ] + @property + def yields(self): + """Return a single information on function yield. + + Takes the first generator information. + """ + for item in self.meta: + if isinstance(item, DocstringReturns) and item.is_generator: + return item + return None + @property def deprecation(self) -> T.Optional[DocstringDeprecated]: """Return a single information on function deprecation notes.""" diff --git a/docstring_parser/tests/test_google.py b/docstring_parser/tests/test_google.py index 201f141..3e93617 100644 --- a/docstring_parser/tests/test_google.py +++ b/docstring_parser/tests/test_google.py @@ -598,6 +598,113 @@ def test_returns() -> None: assert docstring.many_returns[0] == docstring.returns +def test_yields() -> None: + """Test parsing returns.""" + docstring = parse( + """ + Short description + """ + ) + assert docstring.yields is None + + docstring = parse( + """ + Returns: + int: description + """ + ) + assert docstring.yields is None + + docstring = parse( + """ + Short description + Yields: + description + """ + ) + assert docstring.yields is not None + assert docstring.yields.type_name is None + assert docstring.yields.description == "description" + assert docstring.yields.is_generator is True + + docstring = parse( + """ + Short description + Yields: + description with: a colon! + """ + ) + assert docstring.yields is not None + assert docstring.yields.type_name is None + assert docstring.yields.description == "description with: a colon!" + assert docstring.yields.is_generator is True + + docstring = parse( + """ + Short description + Yields: + int: description + """ + ) + assert docstring.yields is not None + assert docstring.yields.type_name == "int" + assert docstring.yields.description == "description" + assert docstring.yields.is_generator is True + + docstring = parse( + """ + Yields: + Optional[Mapping[str, List[int]]]: A description: with a colon + """ + ) + assert docstring.yields is not None + assert docstring.yields.type_name == "Optional[Mapping[str, List[int]]]" + assert docstring.yields.description == "A description: with a colon" + assert docstring.yields.is_generator is True + + docstring = parse( + """ + Short description + Yields: + int: description + with much text + + even some spacing + """ + ) + assert docstring.yields is not None + assert docstring.yields.type_name == "int" + assert docstring.yields.description == ( + "description\nwith much text\n\neven some spacing" + ) + assert docstring.returns.is_generator is True + + docstring = parse( + """ + Returns: + int: description with return first + + Yields: + Optional[Mapping[str, List[int]]]: A description: with a colon + """ + ) + assert docstring.returns is not None + assert docstring.yields is not None + assert docstring.yields.type_name != docstring.returns.type_name + + docstring = parse( + """ + Yields: + Optional[Mapping[str, List[int]]]: A description: with a colon + + Returns: + int: description with return last + """ + ) + assert docstring.returns is not None + assert docstring.yields is not None + assert docstring.yields.type_name == docstring.returns.type_name + def test_raises() -> None: """Test parsing raises.""" docstring = parse( From a7a54844d558605a613d9b8df06e44fe79d852d7 Mon Sep 17 00:00:00 2001 From: Omar Aljarrah <50204418+OmarAlJarrah@users.noreply.github.com> Date: Wed, 20 Dec 2023 16:40:35 +0300 Subject: [PATCH 2/4] Create dependabot.yml --- .github/dependabot.yml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..40db661 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,30 @@ +version: 2 +updates: + # Maintain dependencies for GitHub Actions + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" + time: "11:30" + timezone: "UTC" + target-branch: main + reviewers: + - ExpediaGroup/openworld-committers + labels: + - Dependabot + + # Maintain dependencies for pip + - package-ecosystem: pip + directory: "/" + schedule: + interval: daily + time: "13:35" + timezone: "UTC" + open-pull-requests-limit: 10 + target-branch: main + reviewers: + - ExpediaGroup/openworld-committers + labels: + - Dependabot + commit-message: + prefix: "update " From 3c4d639eb61407ed6df6bc10fe77af88f9414693 Mon Sep 17 00:00:00 2001 From: Omar Aljarrah <50204418+OmarAlJarrah@users.noreply.github.com> Date: Wed, 20 Dec 2023 16:42:12 +0300 Subject: [PATCH 3/4] Create requirements.txt --- requirements.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..6434f16 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +pydoctor~=22.3.0 From 65802e7ea730489176e26119a595052380580f06 Mon Sep 17 00:00:00 2001 From: Omar Aljarrah <50204418+OmarAlJarrah@users.noreply.github.com> Date: Wed, 20 Dec 2023 16:43:01 +0300 Subject: [PATCH 4/4] Update dependabot.yml --- .github/dependabot.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 40db661..6c66a7c 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -18,7 +18,7 @@ updates: directory: "/" schedule: interval: daily - time: "13:35" + time: "13:45" timezone: "UTC" open-pull-requests-limit: 10 target-branch: main