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

"Unexpected indentation" warnings from :members: #4606

Closed
asmeurer opened this issue Feb 12, 2018 · 4 comments
Closed

"Unexpected indentation" warnings from :members: #4606

asmeurer opened this issue Feb 12, 2018 · 4 comments

Comments

@asmeurer
Copy link
Contributor

Since Sphinx updated to 1.7.0, our SymPy docs started failing. We have the setting enabled in our docs to turn warnings into errors.

We have gotten many errors like

Warning, treated as error:
/home/travis/build/sympy/sympy/sympy/codegen/cfunctions.py:docstring of sympy.codegen.cfunctions.exp2.eval:15:Unexpected indentation.
make: *** [html] Error 2

It turns out the source of the error has nothing to do with the method in question (which doesn't even have a docstring). The problem is that we used

.. automodule:: sympy.codegen.cfunctions
    :members:

instead of

.. automodule:: sympy.codegen.cfunctions

   :members:

This is requiring changes across our entire docs.

Now if Sphinx wants to require the newline here, that is fine. But the warning should be much more indicative of what the problem is. Also, quite annoyingly, it only warns about one issue at a time, so if you fix an issue and rebuild, it will warn about another one (and for whatever reason, Sphinx no longer caches the build??? Every build is done from scratch. This is even if I make no changes to anything).

I tested this against the master branch and it is the same result.

Upstream SymPy issue: sympy/sympy#14181

asmeurer added a commit to sympy/sympy that referenced this issue Feb 12, 2018
Apparently, these warnings are caused by not having a newline before
":members:". See sphinx-doc/sphinx#4606.
@asmeurer
Copy link
Contributor Author

Apparently the "one warning at a time" behavior is a result of our use of the -W flag. It would be nice if all warnings were shown, even if they are interpreted as errors at the end of the build.

@tk0miya
Copy link
Member

tk0miya commented Feb 13, 2018

It seems this problem is a combination of two issues.

At first, autodoc_inherit_docstrings feature has been added since 1.7 (for details, please refer our manual).
As a result, a docstring of super class is also used for methods of subclasses automatically. For example, the docstring of sympy.codegen.cfunctions.exp2.eval() is same as sympy.core.function.Function.eval() (because exp2.eval() doesn't have its own docstring).

The next is an issue of markups. It seems docstrings of sympy is not correct. For example, here is the docstring of sympy.core.function.Function.eval().
https://github.com/sympy/sympy/blob/485a06bd38b69d15ab7a3c6a9a62931ebf98dbba/sympy/core/function.py#L280-L303

This docstring contains a example code, but it is not a code-block. So reST parser raises an error "Unexpected indentation.".
With 1.6.7, you can see same warning for autoclass:: sympy.core.function.Function.

.. autoclass:: sympy.core.function.Function
    :members:
root@572ebc7d25ed:/docs# make clean html
Removing everything under '_build'...
Running Sphinx v1.6.7
making output directory...
loading pickled environment... not yet created
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 1 source files that are out of date
updating environment: 1 added, 0 changed, 0 removed
reading sources... [100%] index
/usr/local/lib/python3.5/dist-packages/sympy/core/function.py:docstring of sympy.core.function.Function:6: WARNING: Unexpected section title.

Examples
========
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
writing output... [100%] index
generating indices... genindex
writing additional pages... search
copying static files... done
copying extra files... done
dumping search index in English (code: en) ... done
dumping object inventory... done
build succeeded, 1 warning.

Build finished. The HTML pages are in _build/html.

From these issues, 1.7 causes "Unexpected indentation." warnings.
So I propose you to update your docstrings to correct reST. As a workaround, you can also disable autodoc_inherit_docstrings option. Then

On the other hand, your workaround is not correct.

.. automodule:: sympy.codegen.cfunctions

   :members:

This fix removes :members: option for automodule, and adds members field list as a content.
So members of modules will be vanished.

@asmeurer
Copy link
Contributor Author

Thank you. My top priority was to fix CI build failures in master, so I didn't focus too much on the actual documentation build itself. I'll see if I can fix it correctly, if someone else doesn't do it first.

I think there is a bug here, which is that the error reporting from Sphinx is not very good. It would help a lot if it named the actual function that the docstring came from (Function.eval instead of exp2.eval). There's also the warnings as errors only appearing one at a time issue I mentioned, but that can be a separate issue if you want.

@tk0miya
Copy link
Member

tk0miya commented Feb 13, 2018

I think there is a bug here, which is that the error reporting from Sphinx is not very good. It would help a lot if it named the actual function that the docstring came from (Function.eval instead of exp2.eval).

Absolutely. The messages should be improved.

There's also the warnings as errors only appearing one at a time issue I mentioned, but that can be a separate issue if you want.

Yes please!

@tk0miya tk0miya added this to the 1.7.1 milestone Feb 13, 2018
@tk0miya tk0miya modified the milestones: 1.7.1, 1.7.2 Feb 23, 2018
@tk0miya tk0miya modified the milestones: 1.7.2, 1.7.3 Mar 18, 2018
@tk0miya tk0miya modified the milestones: 1.7.3, 1.8 Apr 22, 2018
@tk0miya tk0miya modified the milestones: 1.8.0, 2.0 Jul 18, 2018
@tk0miya tk0miya modified the milestones: 2.0.0, 2.1.0 Feb 6, 2019
@tk0miya tk0miya modified the milestones: 2.1.0, 2.2.0 Jun 1, 2019
@tk0miya tk0miya modified the milestones: 2.2.0, 2.3.0 Aug 18, 2019
@tk0miya tk0miya modified the milestones: 2.3.0, 2.4.0 Dec 8, 2019
@tk0miya tk0miya modified the milestones: 2.4.0, 3.0.0 Feb 7, 2020
@tk0miya tk0miya modified the milestones: 3.0.0, 3.1.0 Mar 14, 2020
@tk0miya tk0miya modified the milestones: 3.1.0, 3.2.0 May 30, 2020
@tk0miya tk0miya modified the milestones: 3.2.0, 3.3.0 Aug 7, 2020
@tk0miya tk0miya modified the milestones: 3.3.0, 3.4.0 Nov 1, 2020
@tk0miya tk0miya closed this as completed in 2da6de6 Nov 8, 2020
tk0miya added a commit that referenced this issue Nov 8, 2020
…ocstring

Fix #4606: autodoc: the location of the warning is incorrect for inherited method
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 18, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants