Skip to content

Commit 7187aad

Browse files
committed
Add generator test case
1 parent 2161167 commit 7187aad

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

mypyc/test-data/run-generators.test

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -907,3 +907,32 @@ def test_same_names() -> None:
907907
# matches the variable name in the input code, since internally it's generated
908908
# with a prefix.
909909
list(undefined())
910+
911+
[case testGeneratorInheritance]
912+
from typing import Iterator
913+
914+
class Base1:
915+
def foo(self) -> Iterator[int]:
916+
yield 1
917+
918+
class Derived1(Base1):
919+
def foo(self) -> Iterator[int]:
920+
yield 2
921+
yield 3
922+
923+
def base1_foo(b: Base1) -> list[int]:
924+
a = []
925+
for x in b.foo():
926+
a.append(x)
927+
return a
928+
929+
def derived1_foo(b: Derived1) -> list[int]:
930+
a = []
931+
for x in b.foo():
932+
a.append(x)
933+
return a
934+
935+
def test_generator_override() -> None:
936+
assert base1_foo(Base1()) == [1]
937+
assert base1_foo(Derived1()) == [2, 3]
938+
assert derived1_foo(Derived1()) == [2, 3]

0 commit comments

Comments
 (0)