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

google: Allow omitting Yields: if the yield (generator/iterator) type is None #79

Closed
llucax opened this issue Aug 28, 2023 · 3 comments · Fixed by #80
Closed

google: Allow omitting Yields: if the yield (generator/iterator) type is None #79

llucax opened this issue Aug 28, 2023 · 3 comments · Fixed by #80

Comments

@llucax
Copy link
Contributor

llucax commented Aug 28, 2023

The same as Returns: is optional if the return type is None, according to the google style guide it is also optional for Yields:.

Even when this sounds odd to have, it is an useful idiom to write context managers very easily.

import collections.abc
import contextlib


@contextlib.contextmanager
def f() -> collections.abc.Iterator[None]:
    """This function doesn't yield anything."""
    # Some some initialization
    yield
    # Some cleanup


with f():
    print("I'm initialized")

print("I'm cleaned up")
$ pydoclint --style=google --check-return-types=False --check-yield-types=False --skip-checking-short-docstrings=False yieldnone.py
Skipping files that match this pattern: \.git|\.tox
yieldnone.py
yieldnone.py
    6: DOC201: Function `f` does not have a return section in docstring 
    6: DOC402: Function `f` has "yield" statements, but the docstring does not have a "Yields" section 
@jsh9
Copy link
Owner

jsh9 commented Aug 29, 2023

Yes, you are right. I've pushed a code change. It will be included in v0.3.1.

@jsh9 jsh9 closed this as completed in #80 Aug 29, 2023
@jsh9
Copy link
Owner

jsh9 commented Aug 29, 2023

Published.

@jsh9
Copy link
Owner

jsh9 commented Aug 29, 2023

Btw, for this fix to work, the return type would need to be Iterator[None] rather than collections.abc.Iterator[None].

You can read this section for more relevant explanation: https://jsh9.github.io/pydoclint/notes_for_users.html#2-cases-that-pydoclint-is-not-designed-to-handle

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants