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

numpydoc ignore inline comment not recognized when using decorators #495

Closed
sdiebolt opened this issue Aug 24, 2023 · 2 comments · Fixed by #500
Closed

numpydoc ignore inline comment not recognized when using decorators #495

sdiebolt opened this issue Aug 24, 2023 · 2 comments · Fixed by #500

Comments

@sdiebolt
Copy link
Contributor

When using decorators, the numpydoc ignore inline comment does not seem to be recognized by either numpydoc --validate or the validation during Sphinx build. Here's a reprex, stored as test.py:

import functools


def test_decorator(func):
    @functools.wraps(func)
    def wrapper(*args, **kwargs):
        return func(*args, **kwargs)

    return wrapper


@test_decorator
def test_function():  # numpydoc ignore=PR02
    """Test.

    Parameters
    ----------
    x : int
        Test.
    """
    print("test")

Using python -m numpydoc --validate test.test_function raises the warning test.test_function:PR02:Unknown parameters {'x'} when the decorator is used, but doesn't when the decorator is removed. Same thing when using validation during a Sphinx build. Interestingly, validation using python -m numpydoc.hooks.validate_docstrings test.py does not raise the PR02 warning, even when using the decorator.

@sdiebolt
Copy link
Contributor Author

#496 fixes this for all but @property decorated methods. I'll open a follow-up PR to handle these.

@sdiebolt
Copy link
Contributor Author

#500 will allow the validator to handle properties (@property and @cached_property). Note however that custom decorators that don't make use of @functools.wraps or return anything other than the function itself will not be handled by the validator.

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.

1 participant