Skip to content

Commit aba909d

Browse files
add type annotations
1 parent 29213d3 commit aba909d

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

libc/utils/docgen/docgen.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,31 @@
77
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
88
#
99
# ==-------------------------------------------------------------------------==#
10-
from argparse import ArgumentParser
10+
from argparse import ArgumentParser, Namespace
1111
from pathlib import Path
12+
from typing import Dict
1213
import sys
1314
import yaml
1415

1516

16-
def load_api(hname):
17+
def load_api(hname: str) -> Dict:
1718
p = Path(Path(__file__).parent, Path(hname).with_suffix(".yml"))
1819
api = p.read_text(encoding="utf-8")
1920
return yaml.load(api, Loader=yaml.FullLoader)
2021

2122

2223
# TODO: we may need to get more sophisticated for less generic implementations.
2324
# Does libc/src/{hname minus .h suffix}/{fname}.cpp exist?
24-
def is_implemented(hname, fname):
25+
def is_implemented(hname: str, fname: str) -> bool:
2526
return Path(
26-
Path(__file__).resolve().parent.parent.parent,
27+
Path(__file__).parent.parent.parent,
2728
"src",
2829
hname.rstrip(".h"),
2930
fname + ".cpp",
3031
).exists()
3132

3233

33-
def print_functions(header, functions):
34+
def print_functions(header: str, functions: Dict):
3435
for key in sorted(functions.keys()):
3536
print(f" * - {key}")
3637

@@ -46,7 +47,7 @@ def print_functions(header, functions):
4647
print(" -")
4748

4849

49-
def print_header(header, api):
50+
def print_header(header: str, api: Dict):
5051
fns = f"{header} Functions"
5152
print(fns)
5253
print("=" * (len(fns)))
@@ -65,13 +66,10 @@ def print_header(header, api):
6566
print_functions(header, api["functions"])
6667

6768

68-
def get_possible_choices():
69-
return [p.with_suffix(".h").name for p in Path(__file__).parent.glob("*.yml")]
70-
71-
72-
def parse_args():
69+
def parse_args() -> Namespace:
7370
parser = ArgumentParser()
74-
parser.add_argument("header_name", choices=get_possible_choices())
71+
choices = [p.with_suffix(".h").name for p in Path(__file__).parent.glob("*.yml")]
72+
parser.add_argument("header_name", choices=choices)
7573
return parser.parse_args()
7674

7775

0 commit comments

Comments
 (0)