mercurial/patch.py
changeset 52898 9b85f6efcc1d
parent 52691 279e217d6041
--- a/mercurial/patch.py	Sun Feb 16 01:20:24 2025 +0100
+++ b/mercurial/patch.py	Tue Feb 11 21:21:17 2025 -0500
@@ -46,6 +46,8 @@
 )
 
 if typing.TYPE_CHECKING:
+    import email
+
     from typing import (
         Any,
         Iterator,
@@ -279,12 +281,18 @@
     diffs_seen = 0
     ok_types = (b'text/plain', b'text/x-diff', b'text/x-patch')
     message = b''
+
+    part: email.message.Message
     for part in msg.walk():
         content_type = pycompat.bytestr(part.get_content_type())
         ui.debug(b'Content-Type: %s\n' % content_type)
         if content_type not in ok_types:
             continue
-        payload = part.get_payload(decode=True)
+
+        # When decode=True, the only possible return types are bytes or None
+        # for a multipart message.  But it can't be multipart here, because the
+        # Content-Type was just checked.
+        payload = typing.cast(bytes, part.get_payload(decode=True))
         m = diffre.search(payload)
         if m:
             hgpatch = False