Skip to content

Commit c58f43a

Browse files
committed
update __main__
1 parent 5e8946e commit c58f43a

File tree

1 file changed

+2
-25
lines changed

1 file changed

+2
-25
lines changed

typed_stream/__main__.py

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import argparse
1010
import collections
1111
import dataclasses
12+
import inspect
1213
import operator
1314
import sys
1415
import textwrap
@@ -154,30 +155,6 @@ def run_program(options: Options) -> str | None: # noqa: C901
154155
return None
155156

156157

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-
181158
def main() -> str | None: # noqa: C901
182159
"""Parse arguments and then run the program."""
183160
arg_parser = argparse.ArgumentParser(
@@ -210,7 +187,7 @@ def main() -> str | None: # noqa: C901
210187
elif not (doc := cast(str, getattr(method, "__doc__", ""))):
211188
to_print = "No docs."
212189
else:
213-
to_print = dedent_docstring(doc).strip()
190+
to_print = inspect.cleandoc(doc)
214191

215192
print(textwrap.indent(to_print, " " * 4))
216193
return None

0 commit comments

Comments
 (0)