typing: add a few type hints to `mercurial/utils/urlutil.py`
authorMatt Harbison <matt_harbison@yahoo.com>
Wed, 10 Jul 2024 16:04:53 -0400
changeset 51670 a09435c0eb14
parent 51669 32a1c9226dd9
child 51671 6fc31e7bd5db
typing: add a few type hints to `mercurial/utils/urlutil.py` Somewhere between hg 3dbc7b1ecaba and hg 8e3f6b5bf720, `_pathsuboptions` changed from `Dict[bytes, Tuple[bytes, Any]]` to `Dict[bytes, Tuple[str, Any]]`, and it caught my attention from diffing the local *.pyi files. The change is correct based on the assertion, so let's get pytype to check for this instead of relying on the assertion alone.
mercurial/utils/urlutil.py
--- a/mercurial/utils/urlutil.py	Wed Jul 10 15:49:16 2024 -0400
+++ b/mercurial/utils/urlutil.py	Wed Jul 10 16:04:53 2024 -0400
@@ -9,6 +9,9 @@
 import socket
 
 from typing import (
+    Callable,
+    Dict,
+    Tuple,
     Union,
 )
 
@@ -29,7 +32,7 @@
 )
 
 # keeps pyflakes happy
-assert [Union]
+assert [Callable, Dict, Tuple, Union]
 
 urlreq = urllibcompat.urlreq
 
@@ -652,12 +655,12 @@
             self[name] = new_paths
 
 
-_pathsuboptions = {}
+_pathsuboptions: "Dict[bytes, Tuple[str, Callable]]" = {}
 # a dictionnary of methods that can be used to format a sub-option value
 path_suboptions_display = {}
 
 
-def pathsuboption(option, attr, display=pycompat.bytestr):
+def pathsuboption(option: bytes, attr: str, display=pycompat.bytestr):
     """Decorator used to declare a path sub-option.
 
     Arguments are the sub-option name and the attribute it should set on