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

docstrings/sphinx: Support "warn unknown params" feature #64

Closed
pawamoy opened this issue Apr 9, 2022 · 2 comments · Fixed by #210
Closed

docstrings/sphinx: Support "warn unknown params" feature #64

pawamoy opened this issue Apr 9, 2022 · 2 comments · Fixed by #210
Labels
feature New feature or request griffe: docstrings Related to docstring parsing griffe: sphinx Related to Sphinx-style docstrings

Comments

@pawamoy
Copy link
Member

pawamoy commented Apr 9, 2022

When a docstring is parsed, and a parameter is found, and the docstring has a parent function attached, we check that the parameter actually exists in the signature.

The following example should emit a warning:

def increment(a: int) -> int:
    """Increment a number.

    :param b: The number.
    """
    return a + 1
@pawamoy pawamoy added help wanted feature New feature or request griffe: docstrings Related to docstring parsing griffe: sphinx Related to Sphinx-style docstrings labels Apr 9, 2022
@pawamoy pawamoy changed the title docstrings/sphinx: Support "warn unknown params" option docstrings/sphinx: Support "warn unknown params" feature Apr 9, 2022
@Mohamed-Dhouioui
Copy link

Mohamed-Dhouioui commented Apr 9, 2022

I hope the following code would resolve the issue #64 :
image
if __name__ == '__main__': import warnings import inspect doc = inspect.getdoc(increment).split(":") params = [i.replace("param ", "") for i in doc if "param" in i else None] signature = inspect.signature(increment) for param in params: if param not in signature.parameters.keys(): warnings.warn('{} unknown param'.format(param))

@pawamoy
Copy link
Member Author

pawamoy commented Apr 9, 2022

Sorry @Mohamed-Dhouioui but that's really out of touch with the actual code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request griffe: docstrings Related to docstring parsing griffe: sphinx Related to Sphinx-style docstrings
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants