sphinx-doc/sphinx

autodoc does not recognize Cython property as such

Open

#7.448 geöffnet am 9. Apr. 2020

Auf GitHub ansehen
 (3 Kommentare) (1 Reaktion) (0 zugewiesene Personen)Python (1.985 Forks)batch import
extensions:autodochelp wantedtype:enhancement

Repository-Metriken

Stars
 (5.625 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 10T 11h) (11 gemergte PRs in 30 T)

Beschreibung

Because of implementation details, @property of Cython extension types are not the same as created by the builtin property function. For this reason, autodoc doesn't seem to be able to recognize these descriptor as such.

To Reproduce

First create a sample Cython module with the mentioned elements:

getter = property   # bypass Cython property hijack
setter = lambda fset: property(fset=fset, doc=fset.__doc__)     # noqa


cdef class Spam:
    @property
    def foo(self) -> int: return 42

    @getter
    def bar(self) -> float: return 6.9

    @setter
    def baz(self, value: bool) -> None: pass

as well as a setup.py for compilation

from distutils.core import setup
from Cython.Build import cythonize

setup(name='autospam',
      ext_modules=cythonize('cyspam.pyx',
                            compiler_directives={'binding': True}))

Use pip install . to install and cyspam should be importable.

Now if we create a sample project with the following content (I was a bit lazy to think of the documentations for the properties):

.. autoclass:: cyspam.Spam
   :undoc-members:

the rendered HTML looks like this:

2020-04-09T18:21:24

Expected behavior

It is expected that foo shows up as a property as well.

Sample project

autospam.zip

Environment info

  • OS: [e.g. Unix/Linux/Mac/Win/other with version]
  • Python version: 3.7.7
  • Sphinx version: 3.0.0
  • Sphinx extensions: sphinx.ext.autodoc
  • Extra tools: Cython

Contributor Guide