diff --git a/async_generator/_util.py b/async_generator/_util.py index aa6f113..f10096c 100644 --- a/async_generator/_util.py +++ b/async_generator/_util.py @@ -51,9 +51,10 @@ async def __aexit__(self, type, value, traceback): assert value is not None try: await self._agen.athrow(type, value, traceback) - raise RuntimeError( - "async generator didn't stop after athrow()" - ) + if sys.version_info[:3] >= (3, 7, 9) or not isinstance(value, GeneratorExit): + raise RuntimeError( + "async generator didn't stop after athrow()" + ) except StopAsyncIteration as exc: # Suppress StopIteration *unless* it's the same exception # that was passed to throw(). This prevents a