From 3e7ce5d3a1cfe1f3dd6ffc724748259265527f22 Mon Sep 17 00:00:00 2001 From: Rob Ruana Date: Tue, 11 Mar 2014 03:50:49 -0400 Subject: [PATCH] Closes #1418: Private and special members are properly skipped on Python 3.3 --- LICENSE | 4 ++-- sphinx/ext/napoleon/__init__.py | 6 ++++-- sphinx/ext/napoleon/docstring.py | 12 +++++++++--- tests/test_napoleon_docstring.py | 7 ++++--- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/LICENSE b/LICENSE index 85ce4a1dd..c8a792849 100644 --- a/LICENSE +++ b/LICENSE @@ -247,8 +247,8 @@ OTHER DEALINGS IN THE SOFTWARE. ------------------------------------------------------------------------------- -The included implementation of NumpyDocstring._parse_see_also_section was -derived from code under the following license: +The included implementation of NumpyDocstring._parse_numpydoc_see_also_section +was derived from code under the following license: ------------------------------------------------------------------------------- diff --git a/sphinx/ext/napoleon/__init__.py b/sphinx/ext/napoleon/__init__.py index 08ca0eff5..bceabd235 100644 --- a/sphinx/ext/napoleon/__init__.py +++ b/sphinx/ext/napoleon/__init__.py @@ -344,14 +344,16 @@ def _skip_member(app, what, name, obj, skip, options): has_doc = getattr(obj, '__doc__', False) is_member = (what == 'class' or what == 'exception' or what == 'module') if name != '__weakref__' and name != '__init__' and has_doc and is_member: + cls_is_owner = False if what == 'class' or what == 'exception': if sys.version_info[0] < 3: cls = getattr(obj, 'im_class', getattr(obj, '__objclass__', None)) cls_is_owner = (cls and hasattr(cls, name) and name in cls.__dict__) - elif sys.version_info[1] >= 3 and hasattr(obj, '__qualname__'): - cls_path, _, _ = obj.__qualname__.rpartition('.') + elif sys.version_info[1] >= 3: + qualname = getattr(obj, '__qualname__', '') + cls_path, _, _ = qualname.rpartition('.') if cls_path: import importlib import functools diff --git a/sphinx/ext/napoleon/docstring.py b/sphinx/ext/napoleon/docstring.py index d99245c91..24f4423e6 100644 --- a/sphinx/ext/napoleon/docstring.py +++ b/sphinx/ext/napoleon/docstring.py @@ -743,6 +743,13 @@ class NumpyDocstring(GoogleDocstring): r" (?P[a-zA-Z0-9_.-]+))\s*", re.X) def _parse_see_also_section(self, section): + lines = self._consume_to_next_section() + try: + return self._parse_numpydoc_see_also_section(lines) + except ValueError: + return self._format_admonition('seealso', lines) + + def _parse_numpydoc_see_also_section(self, content): """ Derived from the NumpyDoc implementation of _parse_see_also. @@ -752,7 +759,6 @@ class NumpyDocstring(GoogleDocstring): func_name1, func_name2, :meth:`func_name`, func_name3 """ - content = self._consume_to_next_section() items = [] def parse_item_name(text): @@ -777,7 +783,8 @@ class NumpyDocstring(GoogleDocstring): rest = [] for line in content: - if not line.strip(): continue + if not line.strip(): + continue m = self._name_rgx.match(line) if m and line[m.end():].strip().startswith(':'): @@ -799,7 +806,6 @@ class NumpyDocstring(GoogleDocstring): rest.append(line.strip()) push_item(current_func, rest) - if not items: return [] diff --git a/tests/test_napoleon_docstring.py b/tests/test_napoleon_docstring.py index 61b9efe2b..268fc1eb9 100644 --- a/tests/test_napoleon_docstring.py +++ b/tests/test_napoleon_docstring.py @@ -278,8 +278,8 @@ class NumpyDocstringTest(BaseDocstringTest): config = Config(napoleon_use_param=False) actual = str(NumpyDocstring(textwrap.dedent(docstring), config)) expected = textwrap.dedent(""" - :Parameters: **param1** (:class:`MyClass ` instance) - """) +:Parameters: **param1** (:class:`MyClass ` instance) +""") self.assertEqual(expected, actual) config = Config(napoleon_use_param=True) @@ -348,7 +348,8 @@ numpy.multivariate_normal(mean, cov, shape=None, spam=None) config = Config() app = Mock() - actual = str(NumpyDocstring(textwrap.dedent(docstring), config, app, "method")) + actual = str(NumpyDocstring(textwrap.dedent(docstring), + config, app, "method")) expected = """ numpy.multivariate_normal(mean, cov, shape=None, spam=None)