Skip to content

Commit eebdb97

Browse files
committed
fix tests
1 parent 7a7e6c5 commit eebdb97

File tree

2 files changed

+281
-12
lines changed

2 files changed

+281
-12
lines changed

mypyc/test-data/irbuild-basic.test

Lines changed: 275 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3800,7 +3800,7 @@ L0:
38003800
wrapper = r2
38013801
return wrapper
38023802

3803-
[case testStaticMethodGenerator]
3803+
[case testDecoratedGenerator]
38043804
from typing import Iterator
38053805
class C:
38063806
@staticmethod
@@ -3810,10 +3810,282 @@ class C:
38103810
def classgen(cls) -> Iterator[int]:
38113811
yield 1
38123812
[out]
3813+
def staticgen_C_gen.__mypyc_generator_helper__(__mypyc_self__, type, value, traceback, arg, stop_iter_ptr):
3814+
__mypyc_self__ :: __main__.staticgen_C_gen
3815+
type, value, traceback, arg :: object
3816+
stop_iter_ptr :: object_ptr
3817+
r0 :: i32
3818+
r1 :: object
3819+
r2 :: bit
3820+
r3 :: object
3821+
r4 :: bool
3822+
r5 :: object
3823+
r6 :: bit
3824+
r7 :: object
3825+
r8 :: bool
3826+
r9, r10 :: bit
3827+
r11 :: bool
3828+
L0:
3829+
r0 = __mypyc_self__.__mypyc_next_label__
3830+
goto L10
3831+
L1:
3832+
r1 = load_address _Py_NoneStruct
3833+
r2 = type != r1
3834+
if r2 goto L2 else goto L3 :: bool
3835+
L2:
3836+
CPyErr_SetObjectAndTraceback(type, value, traceback)
3837+
unreachable
3838+
L3:
3839+
r3 = object 1
3840+
__mypyc_self__.__mypyc_next_label__ = 1; r4 = is_error
3841+
return r3
3842+
L4:
3843+
r5 = load_address _Py_NoneStruct
3844+
r6 = type != r5
3845+
if r6 goto L5 else goto L6 :: bool
3846+
L5:
3847+
CPyErr_SetObjectAndTraceback(type, value, traceback)
3848+
unreachable
3849+
L6:
3850+
r7 = box(None, 1)
3851+
__mypyc_self__.__mypyc_next_label__ = -1; r8 = is_error
3852+
L7:
3853+
if is_error(stop_iter_ptr) goto L8 else goto L9
3854+
L8:
3855+
CPyGen_SetStopIterationValue(r7)
3856+
unreachable
3857+
L9:
3858+
set_mem stop_iter_ptr, r7 :: builtins.object*
3859+
return 0
3860+
L10:
3861+
r9 = r0 == 0
3862+
if r9 goto L1 else goto L11 :: bool
3863+
L11:
3864+
r10 = r0 == 1
3865+
if r10 goto L4 else goto L12 :: bool
3866+
L12:
3867+
r11 = raise StopIteration
3868+
unreachable
3869+
def staticgen_C_gen.__next__(__mypyc_self__):
3870+
__mypyc_self__ :: __main__.staticgen_C_gen
3871+
r0, r1 :: object
3872+
L0:
3873+
r0 = load_address _Py_NoneStruct
3874+
r1 = staticgen_C_gen.__mypyc_generator_helper__(__mypyc_self__, r0, r0, r0, r0, 0)
3875+
return r1
3876+
def staticgen_C_gen.send(__mypyc_self__, arg):
3877+
__mypyc_self__ :: __main__.staticgen_C_gen
3878+
arg, r0, r1 :: object
3879+
L0:
3880+
r0 = load_address _Py_NoneStruct
3881+
r1 = staticgen_C_gen.__mypyc_generator_helper__(__mypyc_self__, r0, r0, r0, arg, 0)
3882+
return r1
3883+
def staticgen_C_gen.__iter__(__mypyc_self__):
3884+
__mypyc_self__ :: __main__.staticgen_C_gen
3885+
L0:
3886+
return __mypyc_self__
3887+
def staticgen_C_gen.throw(__mypyc_self__, type, value, traceback):
3888+
__mypyc_self__ :: __main__.staticgen_C_gen
3889+
type, value, traceback, r0, r1 :: object
3890+
L0:
3891+
r0 = load_address _Py_NoneStruct
3892+
if is_error(value) goto L1 else goto L2
3893+
L1:
3894+
value = r0
3895+
L2:
3896+
if is_error(traceback) goto L3 else goto L4
3897+
L3:
3898+
traceback = r0
3899+
L4:
3900+
r1 = staticgen_C_gen.__mypyc_generator_helper__(__mypyc_self__, type, value, traceback, r0, 0)
3901+
return r1
3902+
def staticgen_C_gen.close(__mypyc_self__):
3903+
__mypyc_self__ :: __main__.staticgen_C_gen
3904+
r0 :: object
3905+
r1 :: str
3906+
r2, r3, r4, r5 :: object
3907+
r6 :: tuple[object, object, object]
3908+
r7 :: object
3909+
r8 :: str
3910+
r9 :: object
3911+
r10 :: tuple[object, object]
3912+
r11 :: object
3913+
r12 :: bit
3914+
r13 :: object
3915+
r14 :: bool
3916+
L0:
3917+
L1:
3918+
r0 = builtins :: module
3919+
r1 = 'GeneratorExit'
3920+
r2 = CPyObject_GetAttr(r0, r1)
3921+
r3 = load_address _Py_NoneStruct
3922+
r4 = load_address _Py_NoneStruct
3923+
r5 = __mypyc_self__.throw(r2, r3, r4)
3924+
goto L5
3925+
L2: (handler for L1)
3926+
r6 = CPy_CatchError()
3927+
r7 = builtins :: module
3928+
r8 = 'StopIteration'
3929+
r9 = CPyObject_GetAttr(r7, r8)
3930+
r10 = (r2, r9)
3931+
r11 = box(tuple[object, object], r10)
3932+
r12 = CPy_ExceptionMatches(r11)
3933+
if r12 goto L3 else goto L4 :: bool
3934+
L3:
3935+
CPy_RestoreExcInfo(r6)
3936+
r13 = load_address _Py_NoneStruct
3937+
return r13
3938+
L4:
3939+
CPy_Reraise()
3940+
unreachable
3941+
L5:
3942+
r14 = raise RuntimeError('generator ignored GeneratorExit')
3943+
unreachable
38133944
def C.staticgen():
3814-
r0 = CPyGen_Create(...)
3945+
r0 :: __main__.staticgen_C_gen
3946+
r1 :: bool
3947+
L0:
3948+
r0 = staticgen_C_gen()
3949+
r0.__mypyc_next_label__ = 0; r1 = is_error
38153950
return r0
3951+
def classgen_C_gen.__mypyc_generator_helper__(__mypyc_self__, type, value, traceback, arg, stop_iter_ptr):
3952+
__mypyc_self__ :: __main__.classgen_C_gen
3953+
type, value, traceback, arg :: object
3954+
stop_iter_ptr :: object_ptr
3955+
r0 :: i32
3956+
r1 :: object
3957+
r2 :: bit
3958+
r3 :: object
3959+
r4 :: bool
3960+
r5 :: object
3961+
r6 :: bit
3962+
r7 :: object
3963+
r8 :: bool
3964+
r9, r10 :: bit
3965+
r11 :: bool
3966+
L0:
3967+
r0 = __mypyc_self__.__mypyc_next_label__
3968+
goto L10
3969+
L1:
3970+
r1 = load_address _Py_NoneStruct
3971+
r2 = type != r1
3972+
if r2 goto L2 else goto L3 :: bool
3973+
L2:
3974+
CPyErr_SetObjectAndTraceback(type, value, traceback)
3975+
unreachable
3976+
L3:
3977+
r3 = object 1
3978+
__mypyc_self__.__mypyc_next_label__ = 1; r4 = is_error
3979+
return r3
3980+
L4:
3981+
r5 = load_address _Py_NoneStruct
3982+
r6 = type != r5
3983+
if r6 goto L5 else goto L6 :: bool
3984+
L5:
3985+
CPyErr_SetObjectAndTraceback(type, value, traceback)
3986+
unreachable
3987+
L6:
3988+
r7 = box(None, 1)
3989+
__mypyc_self__.__mypyc_next_label__ = -1; r8 = is_error
3990+
L7:
3991+
if is_error(stop_iter_ptr) goto L8 else goto L9
3992+
L8:
3993+
CPyGen_SetStopIterationValue(r7)
3994+
unreachable
3995+
L9:
3996+
set_mem stop_iter_ptr, r7 :: builtins.object*
3997+
return 0
3998+
L10:
3999+
r9 = r0 == 0
4000+
if r9 goto L1 else goto L11 :: bool
4001+
L11:
4002+
r10 = r0 == 1
4003+
if r10 goto L4 else goto L12 :: bool
4004+
L12:
4005+
r11 = raise StopIteration
4006+
unreachable
4007+
def classgen_C_gen.__next__(__mypyc_self__):
4008+
__mypyc_self__ :: __main__.classgen_C_gen
4009+
r0, r1 :: object
4010+
L0:
4011+
r0 = load_address _Py_NoneStruct
4012+
r1 = classgen_C_gen.__mypyc_generator_helper__(__mypyc_self__, r0, r0, r0, r0, 0)
4013+
return r1
4014+
def classgen_C_gen.send(__mypyc_self__, arg):
4015+
__mypyc_self__ :: __main__.classgen_C_gen
4016+
arg, r0, r1 :: object
4017+
L0:
4018+
r0 = load_address _Py_NoneStruct
4019+
r1 = classgen_C_gen.__mypyc_generator_helper__(__mypyc_self__, r0, r0, r0, arg, 0)
4020+
return r1
4021+
def classgen_C_gen.__iter__(__mypyc_self__):
4022+
__mypyc_self__ :: __main__.classgen_C_gen
4023+
L0:
4024+
return __mypyc_self__
4025+
def classgen_C_gen.throw(__mypyc_self__, type, value, traceback):
4026+
__mypyc_self__ :: __main__.classgen_C_gen
4027+
type, value, traceback, r0, r1 :: object
4028+
L0:
4029+
r0 = load_address _Py_NoneStruct
4030+
if is_error(value) goto L1 else goto L2
4031+
L1:
4032+
value = r0
4033+
L2:
4034+
if is_error(traceback) goto L3 else goto L4
4035+
L3:
4036+
traceback = r0
4037+
L4:
4038+
r1 = classgen_C_gen.__mypyc_generator_helper__(__mypyc_self__, type, value, traceback, r0, 0)
4039+
return r1
4040+
def classgen_C_gen.close(__mypyc_self__):
4041+
__mypyc_self__ :: __main__.classgen_C_gen
4042+
r0 :: object
4043+
r1 :: str
4044+
r2, r3, r4, r5 :: object
4045+
r6 :: tuple[object, object, object]
4046+
r7 :: object
4047+
r8 :: str
4048+
r9 :: object
4049+
r10 :: tuple[object, object]
4050+
r11 :: object
4051+
r12 :: bit
4052+
r13 :: object
4053+
r14 :: bool
4054+
L0:
4055+
L1:
4056+
r0 = builtins :: module
4057+
r1 = 'GeneratorExit'
4058+
r2 = CPyObject_GetAttr(r0, r1)
4059+
r3 = load_address _Py_NoneStruct
4060+
r4 = load_address _Py_NoneStruct
4061+
r5 = __mypyc_self__.throw(r2, r3, r4)
4062+
goto L5
4063+
L2: (handler for L1)
4064+
r6 = CPy_CatchError()
4065+
r7 = builtins :: module
4066+
r8 = 'StopIteration'
4067+
r9 = CPyObject_GetAttr(r7, r8)
4068+
r10 = (r2, r9)
4069+
r11 = box(tuple[object, object], r10)
4070+
r12 = CPy_ExceptionMatches(r11)
4071+
if r12 goto L3 else goto L4 :: bool
4072+
L3:
4073+
CPy_RestoreExcInfo(r6)
4074+
r13 = load_address _Py_NoneStruct
4075+
return r13
4076+
L4:
4077+
CPy_Reraise()
4078+
unreachable
4079+
L5:
4080+
r14 = raise RuntimeError('generator ignored GeneratorExit')
4081+
unreachable
38164082
def C.classgen(cls):
38174083
cls :: object
3818-
r0 = CPyGen_Create(...)
4084+
r0 :: __main__.classgen_C_gen
4085+
r1, r2 :: bool
4086+
L0:
4087+
r0 = classgen_C_gen()
4088+
r0.__mypyc_next_label__ = 0; r1 = is_error
4089+
r0.__mypyc_generator_attribute__cls = cls; r2 = is_error
38194090
return r0
4091+

mypyc/test-data/run-generators.test

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -915,9 +915,8 @@ class C:
915915
yield 42
916916

917917
from testutil import run_generator
918-
assert run_generator(C.staticgen()) == ((42,), None)
919-
[out]
920-
42
918+
def test_staticmethod_generator() -> None:
919+
assert run_generator(C.staticgen()) == ((42,), None)
921920

922921
[case testClassMethodGeneratorRuntime]
923922
class C:
@@ -926,9 +925,8 @@ class C:
926925
yield 99
927926

928927
from testutil import run_generator
929-
assert run_generator(C.classgen()) == ((99,), None)
930-
[out]
931-
99
928+
def test_classmethod_generator() -> None:
929+
assert run_generator(C.classgen()) == ((99,), None)
932930

933931
[case testTypePreservingDecoratorGeneratorRuntime]
934932
from typing import Callable, TypeVar
@@ -942,6 +940,5 @@ def gen():
942940
yield 7
943941

944942
from testutil import run_generator
945-
assert run_generator(gen()) == ((7,), None)
946-
[out]
947-
7
943+
def test_type_preserving_decorator() -> None:
944+
assert run_generator(gen()) == ((7,), None)

0 commit comments

Comments
 (0)