# HG changeset patch # User Matt Harbison # Date 2023-02-21 18:24:12 # Node ID 0ab92dabea6ec7d068fb69acf2ffbdfb6b80ef3b # Parent 596a6b9b0570a86702aa2ac446ff980d9e97708e typing: add type hints to pycompat.maplist() The typeshed hints define 5 overloads with an increasing number of parameters on the passed function, and then a catchall that ignores the argument list on the passed function and allows an `*iterators` arg. All of our uses are fulfilled by the 1 function + 1 iterable overload, but add the second overload as a hint in case it's needed in the future. diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py --- a/mercurial/pycompat.py +++ b/mercurial/pycompat.py @@ -32,6 +32,7 @@ from typing import ( Any, AnyStr, BinaryIO, + Callable, Dict, Iterable, Iterator, @@ -58,6 +59,8 @@ if not globals(): # hide this from non- _GetOptResult = Tuple[List[Tuple[bytes, bytes]], List[bytes]] _T0 = TypeVar('_T0') +_T1 = TypeVar('_T1') +_S = TypeVar('_S') _Tbytestr = TypeVar('_Tbytestr', bound='bytestr') @@ -129,8 +132,21 @@ sysplatform: bytes = sys.platform.encode sysexecutable: bytes = os.fsencode(sys.executable) if sys.executable else b'' -def maplist(*args): - return list(map(*args)) +if TYPE_CHECKING: + + @overload + def maplist(f: Callable[[_T0], _S], arg: Iterable[_T0]) -> List[_S]: + ... + + @overload + def maplist( + f: Callable[[_T0, _T1], _S], arg1: Iterable[_T0], arg2: Iterable[_T1] + ) -> List[_S]: + ... + + +def maplist(f, *args): + return list(map(f, *args)) def rangelist(*args):