0

I have this Cython class:

cdef class Sprite:
    def __init__(self, someargument):
        pass

And I want Sphinx to document it like this:

class Sprite(self, texture)
    Does stuff.

so I tried documenting it:

cdef class Sprite:
    def __init__(self, someargument):
        """__init__(self, someargument)

        Does stuff."""

        pass

But it didn't even show up. I even tried this:

cdef class Sprite:
    """Sprite(self, someargument)

    Does stuff."""

    def __init__(self, someargument):
        pass

This time it did show up, but sphinx didn't do it's magic stuff with this information like it normally does:

class Sprite
    Sprite(self, texture)

    Does stuff.

So how must I do it?

mzjn
  • 48,958
  • 13
  • 128
  • 248
orlp
  • 112,504
  • 36
  • 218
  • 315
  • Perhaps your problem is related to insufficient docstring support: http://docs.cython.org/src/reference/extension_types.html?highlight=docstring#docstrings – mzjn Jan 29 '12 at 16:10
  • @mzjn: False, `import pygrafix; pygrafix.sprite.Sprite.__doc__` gives me `"Sprite(self, texture)\n\nblablabla"`. – orlp Jan 29 '12 at 17:03
  • What does the ReST source look like? Does `pygrafix.sprite.Sprite.__init__.__doc__` give you anything? – mzjn Jan 29 '12 at 18:11
  • @mzjn: it's a sphinx bug, apparently. – orlp Jan 29 '12 at 19:08
  • OK, maybe it is a bug. But instead of referring to Sphinx's "magic stuff", can't you show us exactly how to reproduce the bug? In particular, what does your reST markup look like? – mzjn Jan 31 '12 at 11:35
  • @mzjn: My ReST is not interesting at all, it's simply an automodule directive for the respective module. Also, everything worked fine with a pure Python-class. It works like this, sphinx uses the `inspect` module to introspect functions and classes for arguments. If it can't use `inspect` because it detects a built-in or C extension it will try and get the signature from the first line of the docstring. However, this fallback was only added for functions, and forgotten for classes, hence my bug report. – orlp Jan 31 '12 at 11:39

1 Answers1

1

It turned out to be a bug, I added a bug report and a fix here:

https://bitbucket.org/birkenfeld/sphinx/issue/866/sphinx-doesnt-check-an-init-docstring#comment-1012906

orlp
  • 112,504
  • 36
  • 218
  • 315