-
Notifications
You must be signed in to change notification settings - Fork 25
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
Plum2 and interplay between mypy, __doc__ and sphinx #75
Comments
Hey @francesco-ballarin! Thanks for opening this issue. Oof, whereas If we take this as an example from numbers import Number
from plum import dispatch
@dispatch.abstract
def f(x: Number, y: Number):
"""Multiply two numbers."""
@dispatch
def f(x: float, y: float):
"""Multiply two floats."""
return x * y
@dispatch
def f(x: int, y: int):
"""Multiply two ints."""
return x * y then f(x: numbers.Number, y: numbers.Number)
Multiply two numbers.
This function has further implementations documented below.
f(x: float, y: float)
Multiply two floats.
f(x: int, y: int)
Multiply two ints. and 'Multiply two numbers.
This function has further implementations documented below.
f\x08f(x: float, y: float)
Multiply two floats.
f\x08f(x: int, y: int)
Multiply two ints.
' (In the above, I've manually replaced Hence, I can see three issues with the current rendering of
My proposal would be as follows. When generating Instead of
render
(Or any variation on this.) I believe that this should rendered by Sphinx in a readable way. Obviously, it is still a bit of a hack, since really the additional methods should be properly rendered by Sphinx. I refer to @leycec's comment here. How would something like this sound as an intermediate solution until we've got proper Sphinx support? |
Yeah, looks good as a workaround! However, I would probably test in a case which contains
for instance
because I am unsure if having multiple blocks with the same name ( |
Great! And yes, you’re totally right about the test case. I might not have time to work on this in the next week and a half, but after that I should have some time. I’ll keep you posted! |
Sure, no worries! Thanks :) |
Just a brief update! A function with the following docstring def test(x):
"""Test.
Args:
x (int): `x`.
Returns:
int: Sum.
This function has further implementations documented below.
.. py:function:: test(x, y)
Args:
x (int): `x`.
y (int): `y`.
Returns:
int: Sum.
.. py:function:: test(x, y, z)
Args:
x (int): `x`.
y (int): `y`.
z (int): `z`.
Returns:
int: Sum.
""" renders in Sphinx as I don't think that's bad at all! I'll proceed with this format. |
Looks great @wesselb, thanks! |
Perfect, @francesco-ballarin! I'll release a new version this weekend that includes this change. |
Sorry for not having released a new version yet. I'm working on it. I came across a few subtle bugs in the process resolving which is taking a while. |
This has been incorporated in the latest release |
I'm still seeing rendering issues when using something like in @francesco-ballarin's #75 (comment). That is, when using in conjunction with the napoleon extension, sphinx struggles to show the rest of the methods. |
Hey @pabloferz! Damn, I’m sorry to hear that. I thought this was working fine. :( Could you post a screenshot to show how it’s looking like, and perhaps the docstrings as well? |
Hi @wesselb @pabloferz I attach a small module to reproduce the error related to the HTML rendering of the napoleon extension. This is basically the test case from above, properly updated to use |
Hey, is there any chance of decoupling plum's doc mutations from documentation systems? For example, sphinx has custom handling for The challenge with the current approach is that it mutates every docstring with sphinx in mind, but there are several different doc systems (e.g. https://mkdocstrings.github.io/, https://machow.github.io/quartodoc/), and multiple docstring formats. An analogous example might be numpydoc, which uses a sphinx extension to handle some special docstring behaviors. It seems like if we could have (1) a way to disable automatic appending to docstrings, like an environment variable, etc.., then (2) people could figure out hooks into doc systems separately. |
@francesco-ballarin The problem appears the NumPy-style docstrings. Specifically, Plum generates the following docstring for Sphinx:
This renders as ![]() which doesn't properly parse the On the other hand, with Google-style docstrings, we get
which renders as ![]() This does look right, modulo some spacing that can be fixed with CSS. I wonder if there is a way to set this up that it works for both styles of docstrings. |
@machow, definitely! Your suggestion of adding in an env variable or another kind should be simple. What do you envision would be the desired result? Don't append any additional docstrings whenever |
Hey, yeah--something like that would be perfect! Thanks for entertaining all this weird territory of docstrings styles / doc systems 😅. |
@machow This is now implemented on |
@machow Plum |
Hi @wesselb
I was excited to see the improved doc support in #73, and decided to try it out in my project.
As you wrote there, integration with other tools is still an open problem, so I don't expect this issue to be closed any time soon. Still, I'd like to share what workarounds I've tried and how far they got me.
My setup: I have a workflow with
flake8
,mypy
,sphinx
andcoverage
, and they must all pass for the CI run to be successful.To illustrate my workarounds, I refer to https://github.com/RBniCS/RBniCSx/blob/cd02831/rbnicsx/online/projection.py, lines from 39 to 100:
help
;mypy
happy (see mypy crashes with overloads of functools.singledispatch python/mypy#8356 (comment));The good news:
mypy
runs successfully on my workflow,help
command returns the expected documentation.The issues:
mypy
integration is finalized.sphinx
complains thatwhen processing line 100, and the html output looks like the following:
![Screenshot from 2023-03-07 08-06-58](https://user-images.githubusercontent.com/11783908/223349531-ae0c7ee5-87a5-4468-a648-dda742d24f05.png)
where the most noticeable differences from the standard formatting are the spurious ticks (highlighted in blue), and also the different formatting of input/outputs (highlighted in red). This is my configuration file: https://github.com/RBniCS/RBniCSx/blob/cd0283137b244f7963b2c04fd30f9166354b6f28/docs/conf.py. Are there any additional workarounds for this?
__doc__
still has the leading underscore in the dispatched function names. I tried manually replacing_project_vector
->project_vector
, but that didn't seem to replace anything. No big deal anyways ;)Thanks.
The text was updated successfully, but these errors were encountered: