diff mercurial/configuration/rcutil.py @ 52451:91f22b89ea05

config: type `rcutil` It helps to understand what is going on here and catch future errors.
author Pierre-Yves David <pierre-yves.david@octobus.net>
date Tue, 22 Oct 2024 17:23:28 +0200
parents 0a81f3ef054c
children 0b791c90280a
line wrap: on
line diff
--- a/mercurial/configuration/rcutil.py	Mon Oct 21 14:30:50 2024 +0200
+++ b/mercurial/configuration/rcutil.py	Tue Oct 22 17:23:28 2024 +0200
@@ -9,6 +9,14 @@
 
 import os
 
+from typing import (
+    Dict,
+    List,
+    Optional,
+    Tuple,
+    Union,
+)
+
 from .. import (
     encoding,
     pycompat,
@@ -26,8 +34,20 @@
 systemrcpath = scmplatform.systemrcpath
 userrcpath = scmplatform.userrcpath
 
+ConfigItemT = Tuple[bytes, bytes, bytes, bytes]
+ResourceIDT = Tuple[bytes, bytes]
+FileRCT = bytes
+ComponentT = Tuple[
+    bytes,
+    Union[
+        List[ConfigItemT],
+        FileRCT,
+        ResourceIDT,
+    ],
+]
 
-def _expandrcpath(path):
+
+def _expandrcpath(path: bytes) -> List[FileRCT]:
     '''path could be a file or a directory. return a list of file paths'''
     p = util.expandpath(path)
     if os.path.isdir(p):
@@ -38,7 +58,7 @@
     return [p]
 
 
-def envrcitems(env=None):
+def envrcitems(env: Optional[Dict[bytes, bytes]] = None) -> List[ConfigItemT]:
     """Return [(section, name, value, source)] config items.
 
     The config items are extracted from environment variables specified by env,
@@ -61,7 +81,7 @@
     return result
 
 
-def default_rc_resources():
+def default_rc_resources() -> List[ResourceIDT]:
     """return rc resource IDs in defaultrc"""
     rsrcs = resourceutil.contents(b'mercurial.defaultrc')
     return [
@@ -72,7 +92,7 @@
     ]
 
 
-def rccomponents():
+def rccomponents() -> List[ComponentT]:
     """return an ordered [(type, obj)] about where to load configs.
 
     respect $HGRCPATH. if $HGRCPATH is empty, only .hg/hgrc of current repo is
@@ -107,13 +127,13 @@
     return _rccomponents
 
 
-def defaultpagerenv():
+def defaultpagerenv() -> Dict[bytes, bytes]:
     """return a dict of default environment variables and their values,
     intended to be set before starting a pager.
     """
     return {b'LESS': b'FRX', b'LV': b'-c'}
 
 
-def use_repo_hgrc():
+def use_repo_hgrc() -> bool:
     """True if repositories `.hg/hgrc` config should be read"""
     return b'HGRCSKIPREPO' not in encoding.environ