Skip to content

Commit 38e912e

Browse files
committed
doc/tests/manpage-urls.py: Add type annotations
1 parent ba387f0 commit 38e912e

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

doc/tests/manpage-urls.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#! /usr/bin/env nix-shell
22
#! nix-shell -i "python3 -I" -p "python3.withPackages(p: with p; [ aiohttp rich structlog ])"
33

4-
from argparse import ArgumentParser
4+
from argparse import ArgumentParser, Namespace
55
from collections import defaultdict
6+
from collections.abc import Mapping, Sequence
67
from enum import IntEnum
78
from http import HTTPStatus
89
from pathlib import Path
10+
from typing import Optional
911
import asyncio, json, logging
1012

1113
import aiohttp, structlog
@@ -24,7 +26,7 @@
2426
HTTPStatus.NOT_FOUND,
2527
))
2628

27-
async def check(session, manpage: str, url: str) -> HTTPStatus:
29+
async def check(session: aiohttp.ClientSession, manpage: str, url: str) -> HTTPStatus:
2830
with log_context(manpage=manpage, url=url):
2931
logger.debug("Checking")
3032
async with session.head(url) as resp:
@@ -41,12 +43,12 @@ async def check(session, manpage: str, url: str) -> HTTPStatus:
4143

4244
return st
4345

44-
async def main(urls_path):
46+
async def main(urls_path: Path) -> Mapping[HTTPStatus, int]:
4547
logger.info(f"Parsing {urls_path}")
4648
with urls_path.open() as urls_file:
4749
urls = json.load(urls_file)
4850

49-
count = defaultdict(lambda: 0)
51+
count: defaultdict[HTTPStatus, int] = defaultdict(lambda: 0)
5052

5153
logger.info(f"Checking URLs from {urls_path}")
5254
async with aiohttp.ClientSession() as session:
@@ -65,7 +67,7 @@ async def main(urls_path):
6567
return count
6668

6769

68-
def parse_args(args=None):
70+
def parse_args(args: Optional[Sequence[str]] = None) -> Namespace:
6971
parser = ArgumentParser(
7072
prog = 'check-manpage-urls',
7173
description = 'Check the validity of the manpage URLs linked in the nixpkgs manual',

0 commit comments

Comments
 (0)