Commit 9ac9e840 authored by Jörg Thalheim's avatar Jörg Thalheim
Browse files

nixos/test-driver: fix type errors in extract-docstrings

parent a1666863
Loading
Loading
Loading
Loading
+25 −17
Original line number Diff line number Diff line
import ast
import sys
from pathlib import Path

"""
This program takes all the Machine class methods and prints its methods in
@@ -40,10 +41,13 @@ some_function(param1, param2)

"""

assert len(sys.argv) == 2

with open(sys.argv[1], "r") as f:
    module = ast.parse(f.read())
def main() -> None:
    if len(sys.argv) != 2:
        print(f"Usage: {sys.argv[0]} <path-to-test-driver>")
        sys.exit(1)

    module = ast.parse(Path(sys.argv[1]).read_text())

    class_definitions = (node for node in module.body if isinstance(node, ast.ClassDef))

@@ -58,9 +62,13 @@ function_definitions.sort(key=lambda x: x.name)
    for f in function_definitions:
        docstr = ast.get_docstring(f)
        if docstr is not None:
        args = ", ".join((a.arg for a in f.args.args[1:]))
            args = ", ".join(a.arg for a in f.args.args[1:])
            args = f"({args})"

        docstr = "\n".join((f"    {l}" for l in docstr.strip().splitlines()))
            docstr = "\n".join(f"    {l}" for l in docstr.strip().splitlines())

            print(f"{f.name}{args}\n\n:{docstr[1:]}\n")


if __name__ == "__main__":
    main()