keewis / blackdoc

run black on documentation code snippets
https://blackdoc.readthedocs.io
MIT License
47 stars 4 forks source link

Cannot parse doctests like code blocks #166

Closed KelSolaar closed 1 year ago

KelSolaar commented 1 year ago

Hello,

Blackdoc is seemingly unable to parse the following reStructuredText in a Python module:

    -   If precision is required, it is possible to interpolate the
        multi-spectral distributions with :py:class:`scipy.interpolate.interp1d`
        class on the last / tail axis as follows:

        .. code-block:: python

            >>> interpolator = scipy.interpolate.interp1d(
            ...     wavelengths, values, axis=-1, kind="linear",
            ...     fill_value="extrapolate")  # doctest: +SKIP
            >>> values_i = interpolator(wavelengths_i)  # doctest: +SKIP
error: cannot format /Users/kelsolaar/Documents/Development/colour-science/colour/colour/colorimetry/tristimulus_values.py: Cannot parse: 1627:0: >>> interpolator = scipy.interpolate.interp1d(
keewis commented 1 year ago

I'm not sure I understand the difference between this and #165? In any case, trying this with the version from main results in this diff:

--- file.rst    2022-11-01 10:18:10.370537 +0000
+++ file.rst    2022-11-01 10:20:07.750494 +0000
@@ -5,6 +5,6 @@
     .. code-block:: python

        >>> interpolator = scipy.interpolate.interp1d(
-       ...     wavelengths, values, axis=-1, kind="linear",
-       ...     fill_value="extrapolate")  # doctest: +SKIP
+       ...     wavelengths, values, axis=-1, kind="linear", fill_value="extrapolate"
+       ... )  # doctest: +SKIP
        >>> values_i = interpolator(wavelengths_i)  # doctest: +SKIP

so I think this can be closed as a duplicate, as well?

keewis commented 1 year ago

one thing that might be interesting is the doctest comment / pragma. Does that still work if it is on the last line?

KelSolaar commented 1 year ago

I'm not sure I understand the difference between this and https://github.com/keewis/blackdoc/issues/165?

The difference is that #165 occurs in a rst file where here it is in a py file. As there might be potential parsing differences, I made two separate issues but this might very well be the same problem under the hood, I will try your suggestion tonight!

keewis commented 1 year ago

ah, right, that makes sense. And indeed I can confirm that under the hood this is the same problem, which will be fixed with the next release.

KelSolaar commented 1 year ago

Awesome thank you!

keewis commented 1 year ago

I just released a new version. Closing, but feel free to reopen if that didn't fix your issue.

KelSolaar commented 1 year ago

Thanks @keewis, this fixed it perfectly!