|
12 | 12 | # serve to show the default. |
13 | 13 |
|
14 | 14 | #import sys, os |
| 15 | +import re |
15 | 16 |
|
16 | 17 | # If extensions (or modules to document with autodoc) are in another directory, |
17 | 18 | # add these directories to sys.path here. If the directory is relative to the |
@@ -142,24 +143,42 @@ def autodoc_process_docstring(app, what, name, obj, options, lines): |
142 | 143 | if any("Members" in ln for ln in lines): |
143 | 144 | del lines[:] |
144 | 145 |
|
| 146 | + arg_list_re = re.compile(r"^([a-zA-Z0-9_]+)\((.*?)\)") |
| 147 | + |
145 | 148 | from inspect import isclass, isroutine |
146 | 149 | UNDERSCORE_WHITELIST = ["__len__", "__hash__", "__eq__", "__ne__"] # noqa: N806 |
147 | 150 | if isclass(obj) and obj.__name__[0].isupper(): |
148 | 151 | methods = [nm for nm in dir(obj) |
149 | 152 | if isroutine(getattr(obj, nm)) |
150 | 153 | and (not nm.startswith("_") or nm in UNDERSCORE_WHITELIST)] |
151 | 154 |
|
152 | | - def gen_method_string(meth): |
153 | | - result = ":meth:`%s`" % meth |
154 | | - if getattr(obj, "_" + meth + "_is_static", False): |
155 | | - result += " (static)" |
| 155 | + def gen_method_string(meth_name): |
| 156 | + try: |
| 157 | + result = ":meth:`%s`" % meth_name |
| 158 | + meth_obj = getattr(obj, meth_name) |
| 159 | + if meth_obj.__doc__ is None: |
| 160 | + return result |
| 161 | + |
| 162 | + doc_match = arg_list_re.match(meth_obj.__doc__) |
| 163 | + if doc_match is None: |
| 164 | + #print(f"'{meth_obj.__doc__}' did not match arg list RE") |
| 165 | + return result |
| 166 | + |
| 167 | + arg_list = doc_match.group(2).split(", ") |
| 168 | + |
| 169 | + if "self" not in arg_list: |
| 170 | + result += " (static)" |
156 | 171 |
|
157 | | - return result |
| 172 | + return result |
| 173 | + except Exception: |
| 174 | + from traceback import print_exc |
| 175 | + print_exc() |
| 176 | + raise |
158 | 177 |
|
159 | 178 | if methods: |
160 | | - lines[:] = [".. hlist::", " :columns: 3", ""] + [ |
161 | | - " * "+gen_method_string(meth) |
162 | | - for meth in methods] + lines |
| 179 | + lines[:] = [".. hlist::", " :columns: 2", ""] + [ |
| 180 | + " * "+gen_method_string(meth_name) |
| 181 | + for meth_name in methods] + lines |
163 | 182 |
|
164 | 183 | for nm in methods: |
165 | 184 | underscore_autodoc = [] |
|
0 commit comments