Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(common): expose yields as a property. #79

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -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:45"
timezone: "UTC"
open-pull-requests-limit: 10
target-branch: main
reviewers:
- ExpediaGroup/openworld-committers
labels:
- Dependabot
commit-message:
prefix: "update "
11 changes: 11 additions & 0 deletions docstring_parser/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
107 changes: 107 additions & 0 deletions docstring_parser/tests/test_google.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pydoctor~=22.3.0
Loading