about summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorpennae2021-12-18 18:57:45 +0100
committerpennae2022-01-02 19:46:13 +0100
commitb92a47c87cfc4ff750f69d4de54b016e5f53c449 (patch)
tree054672a6d5839ab9453b8ff3d24919cacd54532e /nixos
parentfc614c37c653637e5475a0b0a987489b4d1f351d (diff)
nixos/make-options-doc: add type annotations to mergeJSON.py
Diffstat (limited to 'nixos')
-rw-r--r--nixos/lib/make-options-doc/mergeJSON.py13
1 files changed, 8 insertions, 5 deletions
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(