-
-
Notifications
You must be signed in to change notification settings - Fork 212
add descriptive error message if re.split fails in numpy #784
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
Conversation
|
Thanks! I'd suggest we generically catch all exceptions in except AnyException:
raise RuntimeError(f"Docstring processing failed:\n{content=}\n{source_file=}\n{docformat=}") from e(see pdoc.extract for AnyException - we can move it somewhere else) |
|
Hi, got it - do you want that in addition to the Cheers |
|
Instead of. The point of that is to help debugging and fixing pdoc. I'm happy to merge a second PR that fixes the actual bug in the numpy docstring conversion. |
I'm not sure it is a bug - the NumPy docstring convention requires there to be a type for both in- and output parameters. Sphinx has an extension that takes advantage of python type hints but I think it's just for convenience rather than a newer docstring convention. How would you have suggested to fix the parsing bug otherwise? |
|
|
Now I'm even more confused, since in your first comment you suggested to catch If you meant |
It's not meant to ever throw an exception (but if it does, it should come with useful context for debugging). Phrased differently: If the code has a bug,
Correct, it's not supposed to. If it does, it's a bug. Generally speaking, if something does not parse as a particular format, we should leave the text as-is. I haven't looked super close into the specific numpy case. In either case, that's a separate PR with a test case for more clarity. Thanks! |
|
Okay now I think I get it, thanks for the clarification. What I'll do then is:
|
|
Perfect, thanks! |
|
Okay so it seems the test coverage action fails on these lines: except AnyException as e:
raise RuntimeError(How should I address this? By making a test case in |
|
Yes please. The test needs to mock one of the subfunctions to raise. pytest's monkeypatch is great for that. |
|
Okay, so since I wasn't familiar with monkeypatch I imitated how the There is still a test warning appearing in the logs, however, which seems unrelated to my changes: It looks to me in |
test/test_docstrings.py
Outdated
| assert not s or content or options | ||
|
|
||
|
|
||
| def test_convert_exception(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not a useful test because it tests unwanted behavior (we don't want any known cases of raising). Let's use pytest's monkeypatch to replace rst with a method that raises an exception, and then test with that as you currently do right now (with pytest.raises() is great).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh I see, that makes more sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the new commit look good now?
mhils
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! 🍰 😃
Hi,
I ran into the same issue as reported in #758, and have created a fork to implement the solution proposed by @dhermangh. In its current form, it prints the affected content and the header it's under, but since the individual docstring conversion function does not know which function/class etc. it is operating on, it can't give that info (or a line number in the original file, for that matter). If there is a way to know the latter, I'm happy to add it as well, but for now, it at least suggest to the user that a type descriptor might be missing.
Does this look good to everyone? Happy to include more fixes.
Cheers,
Tobias