|
9 | 9 | import argparse |
10 | 10 | import collections |
11 | 11 | import dataclasses |
| 12 | +import inspect |
12 | 13 | import operator |
13 | 14 | import sys |
14 | 15 | import textwrap |
@@ -154,30 +155,6 @@ def run_program(options: Options) -> str | None: # noqa: C901 |
154 | 155 | return None |
155 | 156 |
|
156 | 157 |
|
157 | | -def dedent_docstring(string: str) -> str: |
158 | | - """Detend a docstring. |
159 | | -
|
160 | | - >>> dedent_docstring("") |
161 | | - '' |
162 | | - >>> dedent_docstring("a") |
163 | | - 'a' |
164 | | - >>> dedent_docstring((" " * 5) + "a") |
165 | | - 'a' |
166 | | - >>> (" " * 2) in dedent_docstring.__doc__ or sys.version_info >= (3, 13) |
167 | | - True |
168 | | - >>> (" " * 2) in dedent_docstring(dedent_docstring.__doc__) |
169 | | - False |
170 | | - >>> dedent_docstring(dedent_docstring.__doc__).endswith("True\\n") |
171 | | - True |
172 | | - """ # noqa: D301 |
173 | | - string = string.removeprefix("\n") |
174 | | - if string.startswith((" ", "\t")): |
175 | | - return textwrap.dedent(string) |
176 | | - split = string.split("\n") |
177 | | - end = textwrap.dedent("\n".join(split[1:])) |
178 | | - return "\n".join([*split[:1], *([end] if end else ())]) |
179 | | - |
180 | | - |
181 | 158 | def main() -> str | None: # noqa: C901 |
182 | 159 | """Parse arguments and then run the program.""" |
183 | 160 | arg_parser = argparse.ArgumentParser( |
@@ -210,7 +187,7 @@ def main() -> str | None: # noqa: C901 |
210 | 187 | elif not (doc := cast(str, getattr(method, "__doc__", ""))): |
211 | 188 | to_print = "No docs." |
212 | 189 | else: |
213 | | - to_print = dedent_docstring(doc).strip() |
| 190 | + to_print = inspect.cleandoc(doc) |
214 | 191 |
|
215 | 192 | print(textwrap.indent(to_print, " " * 4)) |
216 | 193 | return None |
|
0 commit comments