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

Sphinx throws an "unexpected indentation" error for abstract methods #8009

Closed
jtpavlock opened this issue Jul 27, 2020 · 7 comments
Closed

Comments

@jtpavlock
Copy link

jtpavlock commented Jul 27, 2020

Describe the bug
It seems sphinx is not properly detecting abstract private methods and is falsely reported an "undexpected indenation" docstring error.

.. automodule:: nbapy.game
   :members:
   :private-members: _endpoint
   :undoc-members:
   :show-inheritance:
# game.py

class _BoxScore(ABC):
    @property
    @classmethod
    @abstractmethod
    def _endpoint(cls):
        return NotImplementedError

# ... # 

class BoxScore(_BoxScore):
    _endpoint = "boxscoretraditionalv2"
$ sphinx-build -n -W -q -b html docs docs/_build/html

Warning, treated as error:
/home/jacob/src/nbapy/nbapy/game.py:docstring of nbapy.game._BoxScore._endpoint:12:Unexpected indentation.

I'd like to document _endpoint in all the classes that inherit _BoxScore

To Reproduce
Steps to reproduce the behavior:

$ git clone https://github.com/jtpavlock/nbapy
$ cd nbapy
$ poetry install
$ sphinx-build -n -W -q -b html docs docs/_build/html

Expected behavior
Sphinx to not throw this warning

Your project
nbapy

Environment info

  • OS: Ubuntu 20.04
  • Python version: 3.8.2
  • Sphinx version: sphinx-build 3.1.2
  • Sphinx extensions:
extensions = [
    "sphinx.ext.autodoc",
    "sphinx.ext.napoleon",
    "sphinx_rtd_theme",
]
  • Extra tools: none
@tk0miya
Copy link
Member

tk0miya commented Jul 29, 2020

How _BoxScore._endpoint works? I've never seen a property-classmethod.

Note: Internally, autodoc generates the following reST document for your class. It seems autodoc considers the docstring of classmethod class is a docstring of _BoxScore._endpoint. And it is invalid reST...

.. py:class:: _BoxScore()
   :module: example

   Bases: :class:`abc.ABC`


   .. py:attribute:: _BoxScore._abc_impl
      :module: example
      :value: <_abc_data object>


   .. py:method:: _BoxScore._endpoint
      :module: example
      :abstractmethod:
      :property:

      classmethod(function) -> method

      Convert a function to be a class method.

      A class method receives the class as implicit first argument,
      just like an instance method receives the instance.
      To declare a class method, use this idiom:

        class C:
            @classmethod
            def f(cls, arg1, arg2, ...):
                ...

      It can be called either on the class (e.g. C.f()) or on an instance
      (e.g. C().f()).  The instance is ignored except for its class.
      If a class method is called for a derived class, the derived class
      object is passed as the implied first argument.

      Class methods are different than C++ or Java static methods.
      If you want those, see the staticmethod builtin.

@jtpavlock
Copy link
Author

jtpavlock commented Jul 29, 2020

I removed @classmethod and things seem to work fine now, so thanks for picking that out. However, I'm not sure if this is relevant, but I only wish to have _endpoint show up in my documentation, and it seems to be showing all private members.

Does :private-members: _endpoint not do what I expect?

@tk0miya
Copy link
Member

tk0miya commented Jul 29, 2020

Unfortunately, :private-members: option is a kind of flag-option. It does not take arguments.
https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html

@jtpavlock
Copy link
Author

jtpavlock commented Jul 29, 2020

Thanks for the help, I had seen the docs, but wasn't sure if it behaved like :members: or not.

So is there no way to currently do what I am asking without explicitly listing each class and using :autoattribute:?

@tk0miya
Copy link
Member

tk0miya commented Aug 1, 2020

Yes, there is no way to do that at present. But, I think it is reasonable to support it. Could you file another issue please? Then I'll work on it.

@jtpavlock
Copy link
Author

Done #8034! Thanks again for the help.

@tk0miya
Copy link
Member

tk0miya commented Aug 1, 2020

Thanks,

BTW, I think this issue was already resolved. Can I close this?

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 21, 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