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+
12+
1013class BdbQuit (Exception ):
1114 """Exception to give up completely."""
1215
@@ -77,7 +80,7 @@ def dispatch_call(self, frame, arg):
7780 # No need to trace this function
7881 return # None
7982 # Ignore call events in generator except when stepping.
80- if self .stopframe and frame .f_code .co_flags & ( CO_GENERATOR | CO_COROUTINE ) :
83+ if self .stopframe and frame .f_code .co_flags & GENERATOR_AND_COROUTINE_FLAGS :
8184 return self .trace_dispatch
8285 self .user_call (frame , arg )
8386 if self .quitting : raise BdbQuit
@@ -86,7 +89,7 @@ def dispatch_call(self, frame, arg):
8689 def dispatch_return (self , frame , arg ):
8790 if self .stop_here (frame ) or frame == self .returnframe :
8891 # Ignore return events in generator except when stepping.
89- if self .stopframe and frame .f_code .co_flags & ( CO_GENERATOR | CO_COROUTINE ) :
92+ if self .stopframe and frame .f_code .co_flags & GENERATOR_AND_COROUTINE_FLAGS :
9093 return self .trace_dispatch
9194 try :
9295 self .frame_returning = frame
@@ -104,7 +107,7 @@ def dispatch_exception(self, frame, arg):
104107 # When stepping with next/until/return in a generator frame, skip
105108 # the internal StopIteration exception (with no traceback)
106109 # triggered by a subiterator run with the 'yield from' statement.
107- if not (frame .f_code .co_flags & ( CO_GENERATOR | CO_COROUTINE )
110+ if not (frame .f_code .co_flags & GENERATOR_AND_COROUTINE_FLAGS
108111 and arg [0 ] is StopIteration and arg [2 ] is None ):
109112 self .user_exception (frame , arg )
110113 if self .quitting : raise BdbQuit
@@ -113,7 +116,7 @@ def dispatch_exception(self, frame, arg):
113116 # next/until command at the last statement in the generator before the
114117 # exception.
115118 elif (self .stopframe and frame is not self .stopframe
116- and self .stopframe .f_code .co_flags & ( CO_GENERATOR | CO_COROUTINE )
119+ and self .stopframe .f_code .co_flags & GENERATOR_AND_COROUTINE_FLAGS
117120 and arg [0 ] in (StopIteration , GeneratorExit )):
118121 self .user_exception (frame , arg )
119122 if self .quitting : raise BdbQuit
@@ -230,7 +233,7 @@ def set_next(self, frame):
230233
231234 def set_return (self , frame ):
232235 """Stop when returning from the given frame."""
233- if frame .f_code .co_flags & ( CO_GENERATOR | CO_COROUTINE ) :
236+ if frame .f_code .co_flags & GENERATOR_AND_COROUTINE_FLAGS :
234237 self ._set_stopinfo (frame , None , - 1 )
235238 else :
236239 self ._set_stopinfo (frame .f_back , frame )
0 commit comments