autosummary generates incorrect output for staticmethods

Anonymous avatarAnonymous created an issue

I have a file containing

.. autosummary::
  :toctree: generated/

  iocbio.ops.fft_tasks.FFTTasks.load_wisdoms

where the iocbio.ops.fft_tasks contains

class FFTTasks(object):

    @staticmethod
    def load_wisdoms():
        pass

After running sphinx on the above setup, I get warnings:

  ..iocbio/doc/source/generated/iocbio.ops.fft_tasks.FFTTasks.save_wisdoms.rst:6: (WARNING/2) autodoc can't import/find function 'iocbio.ops.fft_tasks.FFTTasks.save_wisdoms', it reported error: "No module named FFTTasks", please check your spelling and sys.path

Apparently, the generated/iocbio.ops.fft_tasks.FFTTasks.save_wisdoms.rst file is incorrect:

iocbio.ops.fft_tasks.FFTTasks.save_wisdoms
==========================================

.. currentmodule:: iocbio.ops.fft_tasks.FFTTasks

.. autofunction:: save_wisdoms

If save_wisdoms would be an ordinary class method, then rst generation works correctly. So, I would expect the following to be correct .rst file:

iocbio.ops.fft_tasks.FFTTasks.save_wisdoms
==========================================

.. currentmodule:: iocbio.ops.fft_tasks

.. autofunction:: FFTTasks.save_wisdoms

Comments (6)

  1. Anonymous

    In addition, when save_wisdoms is classmethod, then the rst output is again correct. So, this is indeed a staticmethod issue. (Now I wonder how decorators in general are handled..)

  2. Anonymous

    In addition, when save_wisdoms is classmethod, then the rst output is again correct. So, this is indeed a staticmethod issue. (Now I wonder how decorators in general are handled..)

  3. Anonymous

    Actually

    .. autofunction:: FFTTasks.save_wisdoms
    

    should read

    .. automethod:: FFTTasks.save_wisdoms
    
  4. Anonymous

    Apparently it is not easy to determine if a function is a new style class static method or not. Anyway, the following patch resolves the issue, that is, it tries harder to import similar to autosummary import_by_name:

    diff -r f2760e4bf1b9 sphinx/ext/autodoc.py
    --- a/sphinx/ext/autodoc.py     Sun Feb 28 15:21:54 2010 +0100
    +++ b/sphinx/ext/autodoc.py     Fri Mar 05 13:31:03 2010 +0200
    @@ -318,8 +318,20 @@ class Documenter(object):
             Returns True if successful, False if an error occurred.
             """
             try:
    -            __import__(self.modname)
    -            obj = self.module = sys.modules[self.modname]
    +            modname = self.modname
    +            objnames = []
    +            while True:
    +                try:
    +                    __import__(modname)
    +                    break
    +                except ImportError, msg:
    +                    if '.' not in modname:
    +                        raise
    +                    modname, objname = modname.rsplit('.', 1)
    +                    objnames.append(objname)
    +            obj = self.module = sys.modules[modname]
    +            for objname in reversed(objnames):
    +                obj = getattr(obj, objname)
                 for part in self.objpath:
                     obj = self.get_attr(obj, part)
                 self.object = obj
    
  5. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.