33import fnmatch
44import sys
55import os
6- from inspect import CO_GENERATOR
6+ from inspect import CO_GENERATOR , CO_COROUTINE
77
88__all__ = ["BdbQuit" , "Bdb" , "Breakpoint" ]
99
@@ -77,7 +77,7 @@ def dispatch_call(self, frame, arg):
7777 # No need to trace this function
7878 return # None
7979 # Ignore call events in generator except when stepping.
80- if self .stopframe and frame .f_code .co_flags & CO_GENERATOR :
80+ if self .stopframe and frame .f_code .co_flags & ( CO_GENERATOR | CO_COROUTINE ) :
8181 return self .trace_dispatch
8282 self .user_call (frame , arg )
8383 if self .quitting : raise BdbQuit
@@ -86,7 +86,7 @@ def dispatch_call(self, frame, arg):
8686 def dispatch_return (self , frame , arg ):
8787 if self .stop_here (frame ) or frame == self .returnframe :
8888 # Ignore return events in generator except when stepping.
89- if self .stopframe and frame .f_code .co_flags & CO_GENERATOR :
89+ if self .stopframe and frame .f_code .co_flags & ( CO_GENERATOR | CO_COROUTINE ) :
9090 return self .trace_dispatch
9191 try :
9292 self .frame_returning = frame
@@ -104,7 +104,7 @@ def dispatch_exception(self, frame, arg):
104104 # When stepping with next/until/return in a generator frame, skip
105105 # the internal StopIteration exception (with no traceback)
106106 # triggered by a subiterator run with the 'yield from' statement.
107- if not (frame .f_code .co_flags & CO_GENERATOR
107+ if not (frame .f_code .co_flags & ( CO_GENERATOR | CO_COROUTINE )
108108 and arg [0 ] is StopIteration and arg [2 ] is None ):
109109 self .user_exception (frame , arg )
110110 if self .quitting : raise BdbQuit
@@ -113,7 +113,7 @@ def dispatch_exception(self, frame, arg):
113113 # next/until command at the last statement in the generator before the
114114 # exception.
115115 elif (self .stopframe and frame is not self .stopframe
116- and self .stopframe .f_code .co_flags & CO_GENERATOR
116+ and self .stopframe .f_code .co_flags & ( CO_GENERATOR | CO_COROUTINE )
117117 and arg [0 ] in (StopIteration , GeneratorExit )):
118118 self .user_exception (frame , arg )
119119 if self .quitting : raise BdbQuit
@@ -230,7 +230,7 @@ def set_next(self, frame):
230230
231231 def set_return (self , frame ):
232232 """Stop when returning from the given frame."""
233- if frame .f_code .co_flags & CO_GENERATOR :
233+ if frame .f_code .co_flags & ( CO_GENERATOR | CO_COROUTINE ) :
234234 self ._set_stopinfo (frame , None , - 1 )
235235 else :
236236 self ._set_stopinfo (frame .f_back , frame )
0 commit comments