diff mercurial/hgweb/webutil.py @ 52892:e02c36478284

typing: add some type annotations around `mercurial.util.sortdict` usage There are a handful of places where this class is used in the generated *.pyi files, and they were mostly showing as `sortdict[nothing, nothing]`. These are the easy ones to fix. There are a few other uses around tags, `revset.py`, and `parser.py`, but the related code looks extremely complicated.
author Matt Harbison <matt_harbison@yahoo.com>
date Sat, 21 Dec 2024 17:43:38 -0500
parents f4733654f144
children b8da7eed1657
line wrap: on
line diff
--- a/mercurial/hgweb/webutil.py	Fri Dec 20 21:14:30 2024 -0500
+++ b/mercurial/hgweb/webutil.py	Sat Dec 21 17:43:38 2024 -0500
@@ -12,6 +12,7 @@
 import difflib
 import os
 import re
+import typing
 
 from ..i18n import _
 from ..node import hex, short
@@ -43,7 +44,16 @@
 
 from ..utils import stringutil
 
-archivespecs = util.sortdict(
+if typing.TYPE_CHECKING:
+    from typing import (
+        Optional,
+    )
+
+    ArchiveSpecT = tuple[bytes, bytes, bytes, Optional[bytes]]
+    """Tuple of (mime-type, archive-type, file extension, encoding)"""
+
+
+archivespecs: util.sortdict[bytes, ArchiveSpecT] = util.sortdict(
     (
         (b'zip', (b'application/zip', b'zip', b'.zip', None)),
         (b'gz', (b'application/x-gzip', b'tgz', b'.tar.gz', None)),