From b92a47c87cfc4ff750f69d4de54b016e5f53c449 Mon Sep 17 00:00:00 2001 From: pennae Date: Sat, 18 Dec 2021 18:57:45 +0100 Subject: nixos/make-options-doc: add type annotations to mergeJSON.py --- nixos/lib/make-options-doc/mergeJSON.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'nixos') diff --git a/nixos/lib/make-options-doc/mergeJSON.py b/nixos/lib/make-options-doc/mergeJSON.py index e7f6897c6d0d..b7dfe2b88e7a 100644 --- a/nixos/lib/make-options-doc/mergeJSON.py +++ b/nixos/lib/make-options-doc/mergeJSON.py @@ -1,9 +1,12 @@ import collections import json import sys +from typing import Any, Dict, List + +JSON = Dict[str, Any] class Key: - def __init__(self, path): + def __init__(self, path: List[str]): self.path = path def __hash__(self): result = 0 @@ -16,8 +19,8 @@ class Key: Option = collections.namedtuple('Option', ['name', 'value']) # pivot a dict of options keyed by their display name to a dict keyed by their path -def pivot(options): - result = dict() +def pivot(options: Dict[str, JSON]) -> Dict[Key, Option]: + result: Dict[Key, Option] = dict() for (name, opt) in options.items(): result[Key(opt['loc'])] = Option(name, opt) return result @@ -25,8 +28,8 @@ def pivot(options): # pivot back to indexed-by-full-name # like the docbook build we'll just fail if multiple options with differing locs # render to the same option name. -def unpivot(options): - result = dict() +def unpivot(options: Dict[Key, Option]) -> Dict[str, JSON]: + result: Dict[str, Dict] = dict() for (key, opt) in options.items(): if opt.name in result: raise RuntimeError( -- cgit 1.4.1