33import fnmatch
44import sys
55import os
6- from inspect import CO_GENERATOR , CO_COROUTINE
6+ from inspect import CO_GENERATOR , CO_COROUTINE , CO_ASYNC_GENERATOR
77
88__all__ = ["BdbQuit" , "Bdb" , "Breakpoint" ]
99
10+ GENERATOR_AND_COROUTINE_FLAGS = CO_GENERATOR | CO_COROUTINE | CO_ASYNC_GENERATOR
11+
1012
1113class BdbQuit (Exception ):
1214 """Exception to give up completely."""
@@ -127,7 +129,7 @@ def dispatch_call(self, frame, arg):
127129 # No need to trace this function
128130 return # None
129131 # Ignore call events in generator except when stepping.
130- if self .stopframe and frame .f_code .co_flags & ( CO_GENERATOR | CO_COROUTINE ) :
132+ if self .stopframe and frame .f_code .co_flags & GENERATOR_AND_COROUTINE_FLAGS :
131133 return self .trace_dispatch
132134 self .user_call (frame , arg )
133135 if self .quitting : raise BdbQuit
@@ -142,7 +144,7 @@ def dispatch_return(self, frame, arg):
142144 """
143145 if self .stop_here (frame ) or frame == self .returnframe :
144146 # Ignore return events in generator except when stepping.
145- if self .stopframe and frame .f_code .co_flags & ( CO_GENERATOR | CO_COROUTINE ) :
147+ if self .stopframe and frame .f_code .co_flags & GENERATOR_AND_COROUTINE_FLAGS :
146148 return self .trace_dispatch
147149 try :
148150 self .frame_returning = frame
@@ -166,7 +168,7 @@ def dispatch_exception(self, frame, arg):
166168 # When stepping with next/until/return in a generator frame, skip
167169 # the internal StopIteration exception (with no traceback)
168170 # triggered by a subiterator run with the 'yield from' statement.
169- if not (frame .f_code .co_flags & ( CO_GENERATOR | CO_COROUTINE )
171+ if not (frame .f_code .co_flags & GENERATOR_AND_COROUTINE_FLAGS
170172 and arg [0 ] is StopIteration and arg [2 ] is None ):
171173 self .user_exception (frame , arg )
172174 if self .quitting : raise BdbQuit
@@ -175,7 +177,7 @@ def dispatch_exception(self, frame, arg):
175177 # next/until command at the last statement in the generator before the
176178 # exception.
177179 elif (self .stopframe and frame is not self .stopframe
178- and self .stopframe .f_code .co_flags & ( CO_GENERATOR | CO_COROUTINE )
180+ and self .stopframe .f_code .co_flags & GENERATOR_AND_COROUTINE_FLAGS
179181 and arg [0 ] in (StopIteration , GeneratorExit )):
180182 self .user_exception (frame , arg )
181183 if self .quitting : raise BdbQuit
@@ -309,7 +311,7 @@ def set_next(self, frame):
309311
310312 def set_return (self , frame ):
311313 """Stop when returning from the given frame."""
312- if frame .f_code .co_flags & ( CO_GENERATOR | CO_COROUTINE ) :
314+ if frame .f_code .co_flags & GENERATOR_AND_COROUTINE_FLAGS :
313315 self ._set_stopinfo (frame , None , - 1 )
314316 else :
315317 self ._set_stopinfo (frame .f_back , frame )
0 commit comments