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 for return annotations using | #66

Closed
haakonvt opened this issue Aug 17, 2023 · 5 comments · Fixed by jsh9/docstring_parser_fork#1 or #67
Closed

False positive for return annotations using | #66

haakonvt opened this issue Aug 17, 2023 · 5 comments · Fixed by jsh9/docstring_parser_fork#1 or #67

Comments

@haakonvt
Copy link

haakonvt commented Aug 17, 2023

I have a few files using the pipe operator instead of typing.Union, and I get what I think looks like a false positive DOC203.

To reproduce:

from typing import Sequence

class Foo:
    pass

class Bar:
    def fn(self, a: Foo | Sequence[Foo]) -> Foo | int:
        """Some description.

        Args:
            a (Foo | Sequence[Foo]): Some description.

        Returns:
            Foo | int: Some description.

        Examples:

            Some examples
        """
        return ...

When running the following file through pydoclint I get the following output:

Loading config from user-specified .toml file: pyproject.toml
Found options defined in pyproject.toml:
{'style': 'google',
 'exclude': 'tests/|scripts/',
 'quiet': True,
 'require_return_section_when_returning_nothing': True,
 'arg_type_hints_in_signature': True,
 'arg_type_hints_in_docstring': True,
 'allow_init_docstring': False,
 'check_return_types': True,
 'check_arg_order': True}
aaaa.py
    9: DOC203: Method `Bar.fn` return type(s) in docstring not consistent with the return annotation. 
    Return annotation types: ['Foo | int']; docstring return section types: ['']

Do I have to use -> Union[Foo, int]:? Or what's wrong here 🤔

@jsh9
Copy link
Owner

jsh9 commented Aug 18, 2023

Hi @haakonvt , thanks for reporting this issue!

I did some research, and this is actually due to a bug in docstring_parser (the docstring parser that pydoclint uses to parse Google-style and Sphinx-style docstrings.

When it sees this

Returns:
    Foo | int: Some description.

it thinks the whole Foo | int: Some description. is the description of the return value.

But it can process Union[Foo, int] correctly.

Let me post an issue over there.

@haakonvt
Copy link
Author

Oh, I see. Thanks for following up @jsh9 😄

@jsh9
Copy link
Owner

jsh9 commented Aug 18, 2023

The fix on the docstring_parser side is not that difficult, just tweaking a regex.

However, there is not a lot of activities on that tool (its last release was almost a year ago, from September 2022). To deliver the fix to pydoclint users quickly, I forked it (https://github.com/jsh9/docstring_parser_fork), fixed it (jsh9/docstring_parser_fork#1), and published the fix to PyPI (https://pypi.org/project/docstring-parser-fork/).

@jsh9 jsh9 closed this as completed in #67 Aug 18, 2023
@jsh9
Copy link
Owner

jsh9 commented Aug 18, 2023

Published. Please try out version 0.1.9: https://github.com/jsh9/pydoclint/releases/tag/0.1.9

@haakonvt
Copy link
Author

Swoosh, I love it! Thanks!

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