diff mercurial/patch.py @ 52691:279e217d6041

typing: lock in the new type annotations detected with the pyupgrade changes After the changes culminating in 70a75d379daf, pytype was able to detect these types better (typically changing from something like `Generator[Any, Any, None]` to `Generator[bytes, Any, None]`). Let's make these explicit so they don't disappear because of other changes.
author Matt Harbison <matt_harbison@yahoo.com>
date Mon, 06 Jan 2025 20:02:17 -0500
parents e627cc25b6f3
children 9b85f6efcc1d
line wrap: on
line diff
--- a/mercurial/patch.py	Wed Jan 15 06:56:44 2025 +0100
+++ b/mercurial/patch.py	Mon Jan 06 20:02:17 2025 -0500
@@ -14,6 +14,7 @@
 import os
 import re
 import shutil
+import typing
 import zlib
 
 from .i18n import _
@@ -44,6 +45,12 @@
     stringutil,
 )
 
+if typing.TYPE_CHECKING:
+    from typing import (
+        Any,
+        Iterator,
+    )
+
 stringio = util.stringio
 
 gitre = re.compile(br'diff --git a/(.*) b/(.*)')
@@ -2792,7 +2799,9 @@
                 nextisnewline = True
 
 
-def difflabel(func, *args, **kw):
+# TODO: first tuple element is likely bytes, but was being detected as bytes|int
+#  so it needs investigation/more typing here.
+def difflabel(func, *args, **kw) -> Iterator[tuple[Any, bytes]]:
     '''yields 2-tuples of (output, label) based on the output of func()'''
     if kw.get('opts') and kw['opts'].worddiff:
         dodiffhunk = diffsinglehunkinline