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

Avoiding rtype checks with typed code: No return type or annotation at ':return: ... #125

Closed
ssbarnea opened this issue Jan 16, 2023 · 5 comments

Comments

@ssbarnea
Copy link

Describe the bug

Once a library adopts type support is it very unlikely that the maintainers will want to duplicate the type information inside the docstrings. That duplication is a real maintenance issue and also a permanent source of bugs, as it is very easy to miss updating the docstring when changing the type.

I personally faced

_warn(docstring, 0, f"No return type or annotation at '{parsed_directive.line}'")
and I see no way to disable that kind of check.

That typing issue is so important that we are willing to switch to a different docstring format.

Currently we use sphinx for historical reasons and anything going towards markdown and less verbosity/duplication would be appealing.

@pawamoy
Copy link
Member

pawamoy commented Jan 16, 2023

Hello, thanks for the report!

I'm a bit confused: this warning is supposed to be emitted only when there is no annotation in the signature and no annotation in the docstring. But I didn't write the sphinx parser so maybe I misunderstood. At least that's how the warnings are supposed to work, and how they actually work in the other two parsers (google and numpy).

Could you show a code snippet that triggers the undesired warning?

@ssbarnea
Copy link
Author

Here is an example that also includes the workaround for it https://github.com/ansible-community/molecule/pull/3811/files#diff-32abfdacc4eeea878460d3bf0ae452ab074ca485bab0b0a01b3bb07775ac002dR399-R630

Basically I removed the return for that one because it did not had any documentation and the type was already documented. I have few other similar places where for example I removed :rtype: line. Excuse the codebase of that project as it was not fully migrated to type, there is a LOT to add to it.

@pawamoy
Copy link
Member

pawamoy commented Jan 16, 2023

The example you linked actually confirms what I said above: https://github.com/ansible-community/molecule/pull/3811/files#diff-32abfdacc4eeea878460d3bf0ae452ab074ca485bab0b0a01b3bb07775ac002dR606-R628

You removed the :return: str line from the docstring of the inventory property, which does not have a return annotation (-> something). If I understand correctly, :return: is meant to give a description, while :rtype: is meant to give a type. Since :return: was present but neither the return annotation or the :rtype: directive were, a warning was emitted.

Or did I misunderstood the Sphinx directives?

@pawamoy
Copy link
Member

pawamoy commented Mar 5, 2023

Closing for now, feel free to reopen if needed.

@pawamoy pawamoy closed this as completed Mar 5, 2023
@SnijderC
Copy link

SnijderC commented Nov 6, 2023

This seems to happen with properties (@property decorated methods). Even if you add the type in the :return: directive, or :rtype:.

@property
def example(self) -> bool:
    """
    Property that returns True for explaining the issue. 
    
    :return: True
    """
    return True

@property
def example2(self) -> bool:
    """
    Property that returns True for explaining the issue. 
    
    :return bool: True
    """
    return True

@property
def example3(self) -> bool:
    """
    Property that returns True for explaining the issue. 
    
    :return: True
    :rtype: bool
    """
    return True

def example4(self) -> bool:
    """
    Property that returns True for explaining the issue. 
    
    :return: True
    """
    return True

Gives:

WARNING -  griffe: test.py:3: No return type or annotation at ':return: True'
WARNING -  griffe: test.py:12: No return type or annotation at ':return bool: True'
WARNING -  griffe: test.py:21: No return type or annotation at ':return: True'

Note the normal method does not trigger a warning, even without a Sphinx style type annotation.

@pawamoy pawamoy reopened this Nov 6, 2023
pawamoy added a commit that referenced this issue Mar 5, 2024
@pawamoy pawamoy closed this as completed Mar 5, 2024
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