Skip to content

Commit

Permalink
optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert committed Dec 29, 2024
1 parent 5e4a262 commit e44b254
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions starlette/_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import functools
import sys
import typing
from contextlib import asynccontextmanager, contextmanager
from contextlib import asynccontextmanager

import anyio.abc

Expand Down Expand Up @@ -74,10 +74,11 @@ async def __aexit__(self, *args: typing.Any) -> None | bool:
return None


@contextmanager
def _collapse_excgroups() -> typing.Generator[None, None, None]:
@asynccontextmanager
async def create_collapsing_task_group() -> typing.AsyncGenerator[anyio.abc.TaskGroup, None]:
try:
yield
async with anyio.create_task_group() as tg:
yield tg
except BaseExceptionGroup as excs:
if len(excs.exceptions) != 1:
raise
Expand All @@ -97,13 +98,6 @@ def _collapse_excgroups() -> typing.Generator[None, None, None]:
del exc, cause, tb, context


@asynccontextmanager
async def create_collapsing_task_group() -> typing.AsyncGenerator[anyio.abc.TaskGroup, None]:
with _collapse_excgroups():
async with anyio.create_task_group() as tg:
yield tg


def get_route_path(scope: Scope) -> str:
path: str = scope["path"]
root_path = scope.get("root_path", "")
Expand Down

0 comments on commit e44b254

Please sign in to comment.