Debian Codegraph @

src/globus_sdk/_internal/extensions/sphinxext/directives/automethodlist.py

raw
1 import types
2 import typing as t
3
4 from docutils.parsers.rst import directives
5
6 from ..utils import classname2methods
7 from .add_content_directive import AddContentDirective
8
9
10 class AutoMethodList(AddContentDirective):
11 has_content = False
12 required_arguments = 1
13 optional_arguments = 0
14 option_spec = {"include_methods": directives.unchanged}
15
16 def gen_rst(self) -> t.Iterator[str]:
17 classname = self.arguments[0]
18
19 include_methods = []
20 if "include_methods" in self.options:
21 include_methods = self.options["include_methods"].strip().split(",")
22
23 yield ""
24 yield "**Methods**"
25 yield ""
26 for methodname, method in classname2methods(classname, include_methods):
27 if not is_paginated_method(method):
28 yield f"* :py:meth:`~{classname}.{methodname}`"
29 else:
30 yield (
31 f"* :py:meth:`~{classname}.{methodname}`, "
32 f"``paginated.{methodname}()``"
33 )
34
35 yield ""
36
37
38 def is_paginated_method(func: types.FunctionType) -> bool:
39 return getattr(func, "_has_paginator", False)