sphinx-contrib / spelling

A spelling checker for Sphinx-based documentation
https://sphinxcontrib-spelling.readthedocs.io/en/latest/
BSD 2-Clause "Simplified" License
82 stars 48 forks source link

Missing return docstring of Protocol.__call__ is causing non-helpful error #216

Closed NMertsch closed 1 year ago

NMertsch commented 1 year ago

(Sorry for not providing a simple reproducible example, after running into dll issues I gave up.)

The following is fine:

from typing import Protocol

class WindowContentProvider(Protocol):
    def __call__(self, app: App, **kwargs: Any) -> Widget | None:
        """Called during app startup to set the initial main window content.

        :return: The initial window content, or ``None``.

        .. note::
            ``**kwargs`` ensures compatibility with additional arguments
            introduced in future versions.
        """
        ...

The following is raising an error (difference: :return: is missing):

class WindowContentProvider(Protocol):
    def __call__(self, app: App, **kwargs: Any) -> Widget | None:
        """Called during app startup to set the initial main window content.

        .. note::
            ``**kwargs`` ensures compatibility with additional arguments
            introduced in future versions.
        """
        ...

Error message:

../.tox/docs-lint/lib/python3.11/site-packages/toga/app.py:docstring of toga.app.WindowContentProvider.__call__:2: : Spell check: rtype: :rtype: .
Writing /home/docs/checkouts/readthedocs.org/user_builds/toga/checkouts/2044/docs/_build/spell/reference/api/app.spelling

This error message was not helpful: There is no misspelling, and there is no rtype. I have no clue why the code triggers an error.

The error occurred during an rtd-triggered build.

dhellmann commented 1 year ago

The spelling checker doesn't have any special handling for docstrings. What is causing the docstring for that method to be included in the documentation set? Is it possible that the autodoc module is adding some default content to the doctree when it does not find explicit details about the return value?

NMertsch commented 1 year ago

Thank you for the context, I created the issue in this repo because the error was reported during sphinx-build [...] -b spelling.

The docstring was included via .. autoprotocol:: toga.app.WindowContentProvider here, provided by the sphinx_toolbox.more_autodoc.autoprotocol extension.

dhellmann commented 1 year ago

The spelling checker just processes the nodes that Sphinx creates, asking each to turn itself into text and then processing the resulting tokens to see if they are in the dictionary. It doesn't have any control over how a node represents itself.

Perhaps the autodoc code is automatically adding an rtype value to the text, either in the plugin you linked to or in the underlying code that comes from Sphinx. You could try a plaintext build to see what the output looks like.

NMertsch commented 1 year ago

Thank you for again. I don't have the time to investigate it in the next days, though. Feel free to close it, since it most likely is an issue with another plugin.

dhellmann commented 1 year ago

Closing since this is not a bug in the spelling checker.

@NMertsch if you do find a useful way to work around this that could be done in the spelling checker, let me know and we can see about bringing that logic into this repo.