From 70f3f889d10add356438137ac0d4f593ff6406a6 Mon Sep 17 00:00:00 2001 From: Takayuki Shimizukawa Date: Sun, 3 Feb 2013 22:27:20 +0900 Subject: [PATCH] Fix autodoc crash if :members: and :special-members: ware both set (by d7ac5e4). --- sphinx/ext/autodoc.py | 1 + tests/test_autodoc.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/sphinx/ext/autodoc.py b/sphinx/ext/autodoc.py index 89680981c..555a31066 100644 --- a/sphinx/ext/autodoc.py +++ b/sphinx/ext/autodoc.py @@ -592,6 +592,7 @@ class Documenter(object): membername != '__doc__': keep = has_doc or self.options.undoc_members elif self.options.special_members and \ + self.options.special_members is not ALL and \ membername in self.options.special_members: keep = has_doc or self.options.undoc_members elif want_all and membername.startswith('_'): diff --git a/tests/test_autodoc.py b/tests/test_autodoc.py index f68f7ab5d..fcd064929 100644 --- a/tests/test_autodoc.py +++ b/tests/test_autodoc.py @@ -90,6 +90,8 @@ def process_signature(app, what, name, obj, options, args, retann): def skip_member(app, what, name, obj, skip, options): + if name in ('__special1__', '__special2__'): + return skip if name.startswith('_'): return True if name == 'skipmeth': @@ -519,6 +521,15 @@ def test_generate(): should.append(('method', 'test_autodoc.Class.inheritedmeth')) assert_processes(should, 'class', 'Class') + # test special members + options.special_members = ['__special1__'] + should.append(('method', 'test_autodoc.Class.__special1__')) + assert_processes(should, 'class', 'Class') + options.special_members = ALL + should.append(('method', 'test_autodoc.Class.__special2__')) + assert_processes(should, 'class', 'Class') + options.special_members = False + options.members = [] # test module flags assert_result_contains('.. py:module:: test_autodoc', @@ -750,6 +761,13 @@ class Class(Base): self.inst_attr_string = None """a documented instance attribute""" + def __special1__(self): + """documented special method""" + + def __special2__(self): + # undocumented special method + pass + class CustomDict(dict): """Docstring."""