diff options
| -rw-r--r-- | CHANGES | 3 | ||||
| -rw-r--r-- | sphinx/ext/autodoc.py | 13 |
2 files changed, 15 insertions, 1 deletions
@@ -78,6 +78,9 @@ New features added - Autodoc now handles inner classes and their methods. + - Autodoc can document classes as functions now if explicitly + marked with `autofunction`. + - There is now a ``Sphinx.add_lexer()`` method to be able to use custom Pygments lexers easily. diff --git a/sphinx/ext/autodoc.py b/sphinx/ext/autodoc.py index d0512f2b..79443859 100644 --- a/sphinx/ext/autodoc.py +++ b/sphinx/ext/autodoc.py @@ -324,7 +324,18 @@ class RstGenerator(object): # can never get arguments of a C function or method getargs = False if getargs: - argspec = inspect.getargspec(obj) + try: + argspec = inspect.getargspec(obj) + except TypeError: + # if a class should be documented as function (yay duck + # typing) we try to use the constructor signature as function + # signature without the first argument. + try: + argspec = inspect.getargspec(obj.__new__) + except TypeError: + argspec = inspect.getargspec(obj.__init__) + if argspec[0]: + del argspec[0][0] if what in ('class', 'method', 'staticmethod', 'classmethod') and argspec[0] and \ argspec[0][0] in ('cls', 'self'): |
