mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
show docs for decorated special functions
This commit is contained in:
@@ -438,7 +438,11 @@ def _skip_member(app: Sphinx, what: str, name: str, obj: Any,
|
||||
mod_path = cls_path.split('.')
|
||||
cls = functools.reduce(getattr, mod_path, mod)
|
||||
else:
|
||||
cls = obj.__globals__[cls_path]
|
||||
if hasattr(obj, '__wrapped__'):
|
||||
# handle functions decorated by @functools.wrap
|
||||
cls = obj.__wrapped__.__globals__[cls_path]
|
||||
else:
|
||||
cls = obj.__globals__[cls_path]
|
||||
except Exception:
|
||||
cls_is_owner = False
|
||||
else:
|
||||
|
||||
@@ -14,6 +14,7 @@ import warnings
|
||||
from io import StringIO
|
||||
from typing import Any, Dict, Generator, IO, List, Pattern
|
||||
from xml.etree import ElementTree
|
||||
import functools
|
||||
|
||||
from docutils import nodes
|
||||
from docutils.nodes import Node
|
||||
@@ -195,3 +196,15 @@ def find_files(root: str, suffix: bool = None) -> Generator[str, None, None]:
|
||||
|
||||
def strip_escseq(text: str) -> str:
|
||||
return re.sub('\x1b.*?m', '', text)
|
||||
|
||||
|
||||
def simple_decorator(f):
|
||||
"""
|
||||
A simple decorator that does nothing, for tests to use.
|
||||
"""
|
||||
@functools.wraps(f)
|
||||
def wrapper(*args, **kwargs):
|
||||
return f(*args, **kwargs)
|
||||
return wrapper
|
||||
|
||||
|
||||
|
||||
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
@@ -14,6 +14,7 @@ from collections import namedtuple
|
||||
from unittest import TestCase, mock
|
||||
|
||||
from sphinx.application import Sphinx
|
||||
from sphinx.testing.util import simple_decorator
|
||||
from sphinx.ext.napoleon import _process_docstring, _skip_member, Config, setup
|
||||
|
||||
|
||||
@@ -50,6 +51,11 @@ class SampleClass:
|
||||
def __special_undoc__(self):
|
||||
pass
|
||||
|
||||
@simple_decorator
|
||||
def __decorated_func__(self):
|
||||
"""doc"""
|
||||
pass
|
||||
|
||||
|
||||
class SampleError(Exception):
|
||||
def _private_doc(self):
|
||||
@@ -130,8 +136,8 @@ class SkipMemberTest(TestCase):
|
||||
self.assertEqual(None, _skip_member(app, what, member, obj, skip,
|
||||
mock.Mock()))
|
||||
else:
|
||||
self.assertFalse(_skip_member(app, what, member, obj, skip,
|
||||
mock.Mock()))
|
||||
self.assertIs(_skip_member(app, what, member, obj, skip,
|
||||
mock.Mock()), False)
|
||||
setattr(app.config, config_name, False)
|
||||
self.assertEqual(None, _skip_member(app, what, member, obj, skip,
|
||||
mock.Mock()))
|
||||
@@ -170,6 +176,11 @@ class SkipMemberTest(TestCase):
|
||||
SampleClass.__special_undoc__, True,
|
||||
'napoleon_include_special_with_doc')
|
||||
|
||||
def test_class_decorated_doc(self):
|
||||
self.assertSkip('class', '__decorated_func__',
|
||||
SampleClass.__decorated_func__, False,
|
||||
'napoleon_include_special_with_doc')
|
||||
|
||||
def test_exception_private_doc(self):
|
||||
self.assertSkip('exception', '_private_doc',
|
||||
SampleError._private_doc, False,
|
||||
|
||||
Reference in New Issue
Block a user