@@ -4646,19 +4646,7 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
4646
4646
if (Py_TYPE (function ) == & PyFunction_Type ) {
4647
4647
PyCodeObject * code = (PyCodeObject * )PyFunction_GET_CODE (function );
4648
4648
STACK_SHRINK (oparg + 1 );
4649
- if (code -> co_flags & (CO_GENERATOR | CO_COROUTINE | CO_ASYNC_GENERATOR )) {
4650
- PyObject * locals = code -> co_flags & CO_OPTIMIZED ? NULL : PyFunction_GET_GLOBALS (function );
4651
- res = make_coro (
4652
- tstate , PyFunction_AS_FRAME_CONSTRUCTOR (function ), locals , stack_pointer + 1 , oparg , NULL );
4653
- for (int i = 0 ; i < oparg + 1 ; i ++ ) {
4654
- Py_DECREF (stack_pointer [i ]);
4655
- }
4656
- PUSH (res );
4657
- if (res == NULL ) {
4658
- goto error ;
4659
- }
4660
- }
4661
- else {
4649
+ if ((code -> co_flags & (CO_GENERATOR | CO_COROUTINE | CO_ASYNC_GENERATOR )) == 0 ) {
4662
4650
InterpreterFrame * new_frame = _PyEval_FrameFromPyFunctionAndArgs (tstate , stack_pointer + 1 , oparg , function );
4663
4651
if (new_frame == NULL ) {
4664
4652
// When we exit here, we own all variables in the stack (the frame creation has not stolen
@@ -4673,15 +4661,23 @@ _PyEval_EvalFrameDefault(PyThreadState *tstate, InterpreterFrame *frame, int thr
4673
4661
tstate -> frame = frame = new_frame ;
4674
4662
goto start_frame ;
4675
4663
}
4664
+ else {
4665
+ /* Callable is a generator or coroutine function: create coroutine or generator. */
4666
+ PyObject * locals = code -> co_flags & CO_OPTIMIZED ? NULL : PyFunction_GET_GLOBALS (function );
4667
+ res = make_coro (tstate , PyFunction_AS_FRAME_CONSTRUCTOR (function ), locals , stack_pointer + 1 , oparg , NULL );
4668
+ for (int i = 0 ; i < oparg + 1 ; i ++ ) {
4669
+ Py_DECREF (stack_pointer [i ]);
4670
+ }
4671
+ }
4676
4672
}
4677
4673
else {
4678
4674
PyObject * * sp = stack_pointer ;
4679
4675
res = call_function (tstate , & sp , oparg , NULL , cframe .use_tracing );
4680
4676
stack_pointer = sp ;
4681
- PUSH ( res );
4682
- if (res == NULL ) {
4683
- goto error ;
4684
- }
4677
+ }
4678
+ PUSH (res );
4679
+ if ( res == NULL ) {
4680
+ goto error ;
4685
4681
}
4686
4682
CHECK_EVAL_BREAKER ();
4687
4683
DISPATCH ();
0 commit comments