Skip to content

Error when handling **kwargs parameters #20

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

Closed
adrienhenry opened this issue Apr 9, 2020 · 4 comments
Closed

Error when handling **kwargs parameters #20

adrienhenry opened this issue Apr 9, 2020 · 4 comments
Labels
bug Something isn't working docstrings Docstrings parsing

Comments

@adrienhenry
Copy link
Contributor

Describe the bug
I get the following error when I document **kwargs parameter in my docstring with the two **.

line 216, in read_parameters_section
    signature_param = self.signature.parameters[name]
KeyError: '**kwargs'

To Reproduce

def function(a, **kwargs):
    """
    Args:
        a: a parameter.
        **kwargs: kwarg parameters
    """
    return None

Information (please complete the following information):

  • OS: Debian
  • mkdocstrings version: [0.7.0]

Additional context
This seems to come from the inspect module as inspect.signature(function).parameters would return:

mappingproxy({'a': <Parameter "a">, 'kwargs': <Parameter "**kwargs">})

and the **kwargs key is not present but kwargs is.

@pawamoy
Copy link
Member

pawamoy commented Apr 9, 2020

Haha yes, I thought about this one this morning again. Indeed we should simply remove the * or ** from param names before searching them in the signature.

Moving the issue to pytkdocs.

@pawamoy pawamoy transferred this issue from mkdocstrings/mkdocstrings Apr 9, 2020
@pawamoy pawamoy added the bug Something isn't working label Apr 9, 2020
@adrienhenry
Copy link
Contributor Author

Can I help with something?
The signature_param = self.signature.parameters[name] to signature_param = self.signature.parameters[name.lstrip("*")] fix the bug.

@pawamoy
Copy link
Member

pawamoy commented Apr 9, 2020

Of course, you can open a PR with this fix if you want! Maybe also add *args and **kwargs somewhere in the docstrings tests 🙂

@pawamoy
Copy link
Member

pawamoy commented Apr 10, 2020

Fixed in #21

@pawamoy pawamoy closed this as completed Apr 10, 2020
@pawamoy pawamoy added the docstrings Docstrings parsing label Apr 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working docstrings Docstrings parsing
Projects
None yet
Development

No branches or pull requests

2 participants