From 88e4e42edc84d141f045bd3c03b48921c0752c66 Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Tue, 19 Apr 2022 19:18:24 +0100 Subject: [PATCH] Add test case for recently fixed `enumerate` regression --- test-data/unit/check-selftype.test | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test-data/unit/check-selftype.test b/test-data/unit/check-selftype.test index 085c522c3013..ef3d5289ddfd 100644 --- a/test-data/unit/check-selftype.test +++ b/test-data/unit/check-selftype.test @@ -1196,3 +1196,27 @@ class C(Generic[T]): for x, y in Z(self.a, self.b): reveal_type((x, y)) # N: Revealed type is "Tuple[T`1, builtins.str]" [builtins fixtures/tuple.pyi] + +[case testEnumerateReturningSelfFromIter] +from typing import Generic, Iterable, Iterator, TypeVar, Tuple + +T = TypeVar("T") +KT = TypeVar("KT") +VT = TypeVar("VT") +Self = TypeVar("Self") + +class enumerate(Iterator[Tuple[int, T]], Generic[T]): + def __init__(self, iterable: Iterable[T]) -> None: ... + def __iter__(self: Self) -> Self: ... + def __next__(self) -> Tuple[int, T]: ... + +class Dict(Generic[KT, VT]): + def update(self, __m: Iterable[Tuple[KT, VT]]) -> None: ... + +class ThingCollection(Generic[T]): + collection: Iterable[Tuple[float, T]] + index: Dict[int, T] + + def do_thing(self) -> None: + self.index.update((idx, c) for idx, (k, c) in enumerate(self.collection)) +[builtins fixtures/tuple.pyi]