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

Catch docstring_parser ValueErrors #19

Merged
merged 1 commit into from
Jan 29, 2021

Conversation

sidnarayanan
Copy link

@sidnarayanan sidnarayanan commented Jan 28, 2021

Some poorly-formatted docstrings can break docstring_parser's parsers, in a way that throws a ValueError. pdocs currently only catches ParseErrors. While normally this means I should fix my docstring, this can be infeasible if the docstrings are inherited from a base class in an external module. See below for an example.

This simple PR catches ValueErrors. There are multiple ways to solve this - could also patch docstring_parser to always throw ParseError. Let me know if that makes more sense.

Example: this docstring will throw the following (calling via portray):

[...]
  File "/data/snarayanan/miniconda3/envs/ge8/lib/python3.8/site-packages/pdocs/doc.py", line 655, in __init__
    super().__init__(name, module, inspect.getdoc(func_obj))
  File "/data/snarayanan/miniconda3/envs/ge8/lib/python3.8/site-packages/pdocs/doc.py", line 154, in __init__
    self.parsed_docstring = docstring_parser.parse(self.docstring)
  File "/data/snarayanan/miniconda3/envs/ge8/lib/python3.8/site-packages/docstring_parser/parser.py", line 21, in parse
    rets.append(parse_(text))
  File "/data/snarayanan/miniconda3/envs/ge8/lib/python3.8/site-packages/docstring_parser/google.py", line 274, in parse
    return GoogleParser().parse(text)
  File "/data/snarayanan/miniconda3/envs/ge8/lib/python3.8/site-packages/docstring_parser/google.py", line 264, in parse
    ret.meta.append(self._build_meta(part, title))
  File "/data/snarayanan/miniconda3/envs/ge8/lib/python3.8/site-packages/docstring_parser/google.py", line 106, in _build_meta
    before, desc = text.split(":", 1)
ValueError: not enough values to unpack (expected 2, got 1)

@Peter200lx
Copy link

Sounds like this is addressing the same issue as #18, is that accurate?

@sidnarayanan
Copy link
Author

Yes indeed! I should've checked existing issues before making the PR.

@timothycrosley
Copy link
Owner

Thank you for fixing this!

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 this pull request may close these issues.

3 participants