summaryrefslogtreecommitdiff
path: root/sphinx/ext/autosummary/generate.py
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2019-05-13 13:53:10 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2019-05-13 13:53:10 +0900
commit743607d4973414445aa1f5e653a5fd4daeb734d0 (patch)
tree5a35420a087e511c7d84d53ae263b5c7272c7025 /sphinx/ext/autosummary/generate.py
parente32a610d7a695421c8439964618c050064e35a0f (diff)
downloadsphinx-git-743607d4973414445aa1f5e653a5fd4daeb734d0.tar.gz
refactor get_members() in autosummary
Diffstat (limited to 'sphinx/ext/autosummary/generate.py')
-rw-r--r--sphinx/ext/autosummary/generate.py17
1 files changed, 6 insertions, 11 deletions
diff --git a/sphinx/ext/autosummary/generate.py b/sphinx/ext/autosummary/generate.py
index c8972b499..eac25697a 100644
--- a/sphinx/ext/autosummary/generate.py
+++ b/sphinx/ext/autosummary/generate.py
@@ -169,13 +169,8 @@ def generate_autosummary_docs(sources, output_dir=None, suffix='.rst',
except TemplateNotFound:
template = template_env.get_template('autosummary/base.rst')
- def get_members(obj, typ, include_public=[], imported=True):
- # type: (Any, Union[str, Set[str]], List[str], bool) -> Tuple[List[str], List[str]] # NOQA
- if isinstance(typ, str):
- types = {typ}
- else:
- types = typ
-
+ def get_members(obj, types, include_public=[], imported=True):
+ # type: (Any, Set[str], List[str], bool) -> Tuple[List[str], List[str]] # NOQA
items = [] # type: List[str]
for name in dir(obj):
try:
@@ -196,17 +191,17 @@ def generate_autosummary_docs(sources, output_dir=None, suffix='.rst',
if doc.objtype == 'module':
ns['members'] = dir(obj)
ns['functions'], ns['all_functions'] = \
- get_members(obj, 'function', imported=imported_members)
+ get_members(obj, {'function'}, imported=imported_members)
ns['classes'], ns['all_classes'] = \
- get_members(obj, 'class', imported=imported_members)
+ get_members(obj, {'class'}, imported=imported_members)
ns['exceptions'], ns['all_exceptions'] = \
- get_members(obj, 'exception', imported=imported_members)
+ get_members(obj, {'exception'}, imported=imported_members)
elif doc.objtype == 'class':
ns['members'] = dir(obj)
ns['inherited_members'] = \
set(dir(obj)) - set(obj.__dict__.keys())
ns['methods'], ns['all_methods'] = \
- get_members(obj, 'method', ['__init__'])
+ get_members(obj, {'method'}, ['__init__'])
ns['attributes'], ns['all_attributes'] = \
get_members(obj, {'attribute', 'property'})