Skip to content
Snippets Groups Projects
Commit 0ab92dab authored by Matt Harbison's avatar Matt Harbison
Browse files

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.
parent 596a6b9b
No related branches found
No related tags found
2 merge requests!485branching: merge default into stable,!456typing: add type hints to pycompat.maplist()
......@@ -32,6 +32,7 @@
Any,
AnyStr,
BinaryIO,
Callable,
Dict,
Iterable,
Iterator,
......@@ -58,6 +59,8 @@
_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 @@
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):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment