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

False positive DOC201 #125

Closed
ddelange opened this issue Feb 21, 2024 · 4 comments
Closed

False positive DOC201 #125

ddelange opened this issue Feb 21, 2024 · 4 comments

Comments

@ddelange
Copy link

Hi 👋

This function edits inplace and doesn't have a return value:

def smoothen_values(list_smooth: list[str], key: str):
    """Edit list_smooth inplace.

    Args:
        list_smooth: A list with keys.
        key: The key to add.
    """
    if len(list_smooth) <= 1:
        return
    list_smooth += [key]

It throws a DOC201: Function smoothen_values does not have a return section in docstring false positive.

@jsh9
Copy link
Owner

jsh9 commented Mar 1, 2024

Interesting. This is an edge case that this option does not cover: https://jsh9.github.io/pydoclint/config_options.html#9---require-return-section-when-returning-nothing-shortform--rrs-default-false

I think I'll add a patch to cover this case.

@jsh9
Copy link
Owner

jsh9 commented Jan 12, 2025

Hi @ddelange , upon double checking, I found that this is by design rather than a bug.

I actually even have a test case to cover this:

def func5(text: str):
"""A return section is always required because it has explicit "return"
in the function body (even if it is just "return")
Args:
text (str): Text for the function
"""
return

@ddelange
Copy link
Author

OK, let's leave it at that then 👍

@ddelange ddelange closed this as not planned Won't fix, can't repro, duplicate, stale Jan 13, 2025
@krispycheez
Copy link

I see that this is already closed, but was wondering if you could go into more detail about the rationale behind handling this edge case in this way. The way I am interpreting it, you are assuming that the function writer specifically chose to use "return" when it was not required. Therefore, they should have to add a section to the docstring because this is not a normal "return nothing" function. But in more complex functions, "return" might be used to escape a deeply nested set of conditionals, and is arguably required (at least without having to restructure the logic of the function). I would personally consider such a function a normal "return nothing" function that should not require a Returns section in the docstring.

My two cents is a "Returns" docstring section should only be required if there is an empty "return" statement in the function that is not conditional (i.e. the last line of the function is "return"). The test you posted would still work as desired in that case and require a "Returns" section in the docstring, but the original example posted would not require it.

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

No branches or pull requests

3 participants