File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
graalpython/com.oracle.graal.python.test/src/tests Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -256,6 +256,36 @@ def f():
256
256
# self.assertTrue(isinstance(cm.exception.value, StopIteration))
257
257
# self.assertEqual(cm.exception.value.value, 2)
258
258
259
+ def test_generator_caller_frame (self ):
260
+ def gen ():
261
+ yield sys ._getframe (1 )
262
+ yield sys ._getframe (1 )
263
+
264
+ def callnext (g ):
265
+ next (g )
266
+ return next (g )
267
+
268
+ def callsend (g ):
269
+ next (g )
270
+ return g .send (1 )
271
+
272
+ self .assertEqual (callnext (gen ()).f_code .co_name , 'callnext' )
273
+ self .assertEqual (callsend (gen ()).f_code .co_name , 'callsend' )
274
+
275
+ # Force a megamorphic call to the genrator function
276
+ def genfn (i ):
277
+ l = {}
278
+ exec (f"def f{ i } (): yield { i } " , l )
279
+ return l [f'f{ i } ' ]
280
+
281
+ fns = [genfn (i ) for i in range (100 )]
282
+ fns .append (gen )
283
+ for fn in fns :
284
+ g = fn ()
285
+ self .assertEqual (callnext (g ).f_code .co_name , 'callnext' )
286
+ for fn in fns :
287
+ g = fn ()
288
+ self .assertEqual (callsend (g ).f_code .co_name , 'callsend' )
259
289
260
290
if sys .version_info .minor == 4 and sys .version_info .micro < 3 :
261
291
del ExceptionTest
You can’t perform that action at this time.
0 commit comments