mercurial/diffutil.py
changeset 50252 a6b8b1ab9116
parent 49898 024e0580b853
parent 50247 b8cac4e37100
child 51143 d6e5bec550f1
--- a/mercurial/diffutil.py	Thu Mar 02 04:16:47 2023 +0100
+++ b/mercurial/diffutil.py	Thu Mar 02 19:02:52 2023 +0100
@@ -7,6 +7,13 @@
 # This software may be used and distributed according to the terms of the
 # GNU General Public License version 2 or any later version.
 
+import typing
+
+from typing import (
+    Any,
+    Dict,
+    Optional,
+)
 
 from .i18n import _
 
@@ -15,10 +22,20 @@
     pycompat,
 )
 
+if typing.TYPE_CHECKING:
+    from . import ui as uimod
+
+# TODO: narrow the value after the config module is typed
+_Opts = Dict[bytes, Any]
+
 
 def diffallopts(
-    ui, opts=None, untrusted=False, section=b'diff', configprefix=b''
-):
+    ui: "uimod.ui",
+    opts: Optional[_Opts] = None,
+    untrusted: bool = False,
+    section: bytes = b'diff',
+    configprefix: bytes = b'',
+) -> mdiff.diffopts:
     '''return diffopts with all features supported and parsed'''
     return difffeatureopts(
         ui,
@@ -33,15 +50,15 @@
 
 
 def difffeatureopts(
-    ui,
-    opts=None,
-    untrusted=False,
-    section=b'diff',
-    git=False,
-    whitespace=False,
-    formatchanging=False,
-    configprefix=b'',
-):
+    ui: "uimod.ui",
+    opts: Optional[_Opts] = None,
+    untrusted: bool = False,
+    section: bytes = b'diff',
+    git: bool = False,
+    whitespace: bool = False,
+    formatchanging: bool = False,
+    configprefix: bytes = b'',
+) -> mdiff.diffopts:
     """return diffopts with only opted-in features parsed
 
     Features:
@@ -51,7 +68,12 @@
       with most diff parsers
     """
 
-    def get(key, name=None, getter=ui.configbool, forceplain=None):
+    def get(
+        key: bytes,
+        name: Optional[bytes] = None,
+        getter=ui.configbool,
+        forceplain: Optional[bool] = None,
+    ) -> Any:
         if opts:
             v = opts.get(key)
             # diffopts flags are either None-default (which is passed