Mercurial > public > mercurial-scm > hg-stable
changeset 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 | b1daf3064362 |
children | 6ce3fc909a68 |
files | hgext/phabricator.py mercurial/bundle2.py mercurial/hgweb/webutil.py |
diffstat | 3 files changed, 15 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/phabricator.py Fri Dec 20 21:14:30 2024 -0500 +++ b/hgext/phabricator.py Sat Dec 21 17:43:38 2024 -0500 @@ -1691,7 +1691,7 @@ # Map from "hg:meta" keys to header understood by "hg import". The order is # consistent with "hg export" output. -_metanamemap = util.sortdict( +_metanamemap: util.sortdict[bytes, bytes] = util.sortdict( [ (b'user', b'User'), (b'date', b'Date'),
--- a/mercurial/bundle2.py Fri Dec 20 21:14:30 2024 -0500 +++ b/mercurial/bundle2.py Sat Dec 21 17:43:38 2024 -0500 @@ -869,7 +869,9 @@ params = self._processallparams(params) return params - def _processallparams(self, paramsblock): + def _processallparams( + self, paramsblock: bytes + ) -> util.sortdict[bytes, bytes]: """ """ params = util.sortdict() for p in paramsblock.split(b' '):
--- 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)),