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

ValueError when using griffe as a docstring parser #51

Closed
rudolfbyker opened this issue Feb 23, 2022 · 2 comments
Closed

ValueError when using griffe as a docstring parser #51

rudolfbyker opened this issue Feb 23, 2022 · 2 comments

Comments

@rudolfbyker
Copy link
Contributor

Describe the bug

When using Griffe as a docstring-parsing library according to https://mkdocstrings.github.io/griffe/usage/#using-griffe-as-a-docstring-parsing-library , we sometimes get ValueError at

https://github.com/mkdocstrings/griffe/blob/master/src/griffe/dataclasses.py#L497

... which is caused by the warning method

https://github.com/mkdocstrings/griffe/blob/master/src/griffe/docstrings/utils.py#L37

... which is called from

https://github.com/mkdocstrings/griffe/blob/master/src/griffe/docstrings/google.py#L189

... when an annotation is missing.

To Reproduce

Run this:

from griffe.dataclasses import Docstring, Function, Parameters, Parameter
from griffe.docstrings.google import parse

if __name__ == "__main__":
    parsed_docstring = parse(
        Docstring(
            value="""\
A function.

Args:
    a: Whatever

Returns:
    Nothing.
""",
            lineno=1,
            parent=Function(
                name="foo",
                parameters=Parameters(
                    Parameter(
                        name="a",
                        annotation=None,
                        default="5",
                    )
                ),
            ),
        )
    )

Expected behavior
No error, just the usual warning. The warning need not contain the file path if there is no file path.

System (please complete the following information):

  • griffe version: 0.13.0
  • Python version: 3.7
  • OS: Windows

Additional context
Add any other context about the problem here.

@rudolfbyker
Copy link
Contributor Author

Another example, from the docs, but without annotation:

from griffe.dataclasses import Docstring, Function, Parameters, Parameter, ParameterKind
from griffe.docstrings.parsers import Parser, parse

function = Function(
    "func",
    parameters=Parameters(
        Parameter("param1", annotation=None, kind=ParameterKind.positional_or_keyword),  # I only changed this line
        Parameter("param2", annotation="int", kind=ParameterKind.keyword_only),
    ),
)
text = """
Hello I'm a docstring!

Parameters:
    param1: Description.
    param2: Description.
"""
docstring = Docstring(text, lineno=1, parent=function)
parsed = parse(docstring, Parser.google)

@pawamoy
Copy link
Member

pawamoy commented Feb 24, 2022

Thanks for the report! This is fixed in master (will push and release soon).

@pawamoy pawamoy closed this as completed Feb 24, 2022
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

No branches or pull requests

2 participants