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 positives for DOC503? #165

Closed
sondrfos opened this issue Sep 3, 2024 · 8 comments · Fixed by #168
Closed

False positives for DOC503? #165

sondrfos opened this issue Sep 3, 2024 · 8 comments · Fixed by #168

Comments

@sondrfos
Copy link

sondrfos commented Sep 3, 2024

Hello,

Thank you for maintaining the great tool pydoclint!
We were about to merge 0.5.7 to our project, but it seems as though the newly added rule DOC503 results in some false positives.

Let me try to give a minimal example:

class CredentialsValidationError(Exception):
    pass

This exception-definition is located in a file called exceptions.py

Then another file imports the entire exceptions.py and uses the CredentialsValidationError-exception from this file

import exceptions

def foo():
    """Bar.

    Raises:
        exceptions.CredentialsValidationError: An exception
    """
    raise exceptions.CredentialsValidationError

This results in a DOC503-error with the message

DOC503: Function `foo` exceptions in the "Raises" section in the docstring do not match those in the function body Raises values in the docstring: ['exceptions.CredentialsValidationError']. Raised exceptions in the body: ['exceptions'].

Is this intended behaviour? Is there somthing here I dont understand?
Thanks!

@jsh9
Copy link
Owner

jsh9 commented Sep 4, 2024

Hi @sondrfos : thank you for finding this issue!

Hi @Amar1729 , I was able to reproduce this issue, and I found that it occurred in these lines:

for subnode, _ in walk.walk_dfs(child):
if isinstance(subnode, ast.Name):
yield subnode.id
break

Using the example above, subnode.id is exceptions, and child.exc.attr is CredentialsValidationError.

Do you have a simply and quick way to fix this? Thanks!

@Amar1729
Copy link
Contributor

Amar1729 commented Sep 4, 2024

I do love more edge cases 😉

I'll take a look!

@jonyscathe
Copy link

Any update on this?
Am getting the same sort of error on a raise httpx.ConnectError (raised in a test fixture):

exceptions in the "Raises" section in the docstring do not match those in the function body Raises values in the docstring: ['ConnectError']. Raised exceptions in the body: ['httpx']

I can obviously get around this by importing ConnectError from httpx separately to the rest of the package, but not ideal to have to do so.

@jsh9
Copy link
Owner

jsh9 commented Sep 18, 2024

I'm working on a potential solution now, and I'll create a PR soon (in a few days).

@Amar1729
Copy link
Contributor

hey @jsh9 sorry for the delay on this. work got a little crazy and i forgot about this notif. just pushed up a change

@Apakottur
Copy link

I'm encountering what I think is the same issue but am not sure:

# test.py
import test2


def func() -> None:
    """
    text

    Raises:
        test2.MyException: exception
    """

    try:
        x = 1
    except test2.MyException:
        raise
# test2.py
class MyException(Exception):
    pass

When running pydoclint I get:

test.py:4:1: DOC503 Function `func` exceptions in the "Raises" section in the docstring do not match those in the function body Raises values in the docstring: ['test2.MyException']. Raised exceptions in the body: [].

@Amar1729
Copy link
Contributor

Amar1729 commented Sep 20, 2024

@Apakottur that is the same issue, thanks for reporting. Looks like that situation isn't caught by my PR; working on an update updated.

@jsh9 jsh9 closed this as completed in #168 Sep 23, 2024
@jsh9
Copy link
Owner

jsh9 commented Sep 23, 2024

Published 0.5.8 on PyPI.

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.

5 participants