Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lite_bootstrap/bootstrappers/fastapi_bootstrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import dataclasses
import time
import typing
from collections.abc import AsyncGenerator

from lite_bootstrap import import_checker
from lite_bootstrap.bootstrappers.base import BaseBootstrapper
Expand Down Expand Up @@ -264,7 +265,7 @@ class FastAPIBootstrapper(BaseBootstrapper["fastapi.FastAPI"]):
not_ready_message = "fastapi is not installed"

@contextlib.asynccontextmanager
async def lifespan_manager(self, _: "fastapi.FastAPI") -> typing.AsyncIterator[dict[str, typing.Any]]:
async def lifespan_manager(self, _: "fastapi.FastAPI") -> AsyncGenerator[dict[str, typing.Any]]:
try:
yield {}
finally:
Expand Down
3 changes: 2 additions & 1 deletion lite_bootstrap/bootstrappers/fastmcp_bootstrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import dataclasses
import time
import typing
from collections.abc import AsyncGenerator

from lite_bootstrap import import_checker
from lite_bootstrap.bootstrappers.base import BaseBootstrapper
Expand Down Expand Up @@ -42,7 +43,7 @@ def __init__(self, teardown: typing.Callable[[], None]) -> None:
self._teardown = teardown

@contextlib.asynccontextmanager
async def lifespan(self) -> typing.AsyncIterator[None]:
async def lifespan(self) -> AsyncGenerator[None]:
try:
yield
finally:
Expand Down
6 changes: 3 additions & 3 deletions lite_bootstrap/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import contextlib
import logging
import typing
from collections.abc import Generator


class LiteBootstrapError(RuntimeError):
Expand Down Expand Up @@ -44,7 +44,7 @@ def __init__(self, logger: logging.Logger | None = None) -> None:
self._logger = logger

@contextlib.contextmanager
def capture(self, name: str) -> typing.Iterator[None]:
def capture(self, name: str) -> Generator[None]:
"""Record an ``Exception`` raised by one teardown step under ``name`` and continue."""
try:
yield
Expand All @@ -55,7 +55,7 @@ def capture(self, name: str) -> typing.Iterator[None]:


@contextlib.contextmanager
def collect_teardown_errors(logger: logging.Logger | None = None) -> typing.Iterator[TeardownErrorCollector]:
def collect_teardown_errors(logger: logging.Logger | None = None) -> Generator[TeardownErrorCollector]:
"""Collect the failures of individual teardown steps and raise them together.

Raises :class:`TeardownError` on leaving the block if any ``capture()`` recorded
Expand Down
5 changes: 3 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sys
import typing
import warnings
from collections.abc import Generator
from importlib import reload

import opentelemetry.metrics._internal
Expand Down Expand Up @@ -89,7 +90,7 @@ def warning_source_files(caught: typing.Iterable[warnings.WarningMessage], categ


@contextlib.contextmanager
def emulate_package_missing(package_name: str) -> typing.Iterator[None]:
def emulate_package_missing(package_name: str) -> Generator[None]:
old_module = sys.modules[package_name]
sys.modules[package_name] = None # ty: ignore[invalid-assignment]
reload(import_checker)
Expand All @@ -103,7 +104,7 @@ def emulate_package_missing(package_name: str) -> typing.Iterator[None]:
@contextlib.contextmanager
def emulate_package_missing_with_module_reload(
package_name: str, module_names: typing.Iterable[str]
) -> typing.Iterator[None]:
) -> Generator[None]:
# Reload listed modules under emulate_package_missing so their
# `if import_checker.is_X_installed: import X` blocks re-evaluate against
# the patched flag. `importlib.reload` preserves existing module globals,
Expand Down
5 changes: 3 additions & 2 deletions tests/test_fastapi_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import typing
import uuid
import warnings
from collections.abc import Generator
from unittest.mock import patch

import fastapi
Expand Down Expand Up @@ -290,7 +291,7 @@ def access_logger() -> typing.Iterator[RecordingAccessLogger]:


@contextlib.contextmanager
def _bootstrapped(config: FastAPIConfig) -> typing.Iterator["fastapi.FastAPI"]:
def _bootstrapped(config: FastAPIConfig) -> Generator["fastapi.FastAPI"]:
bootstrapper = FastAPIBootstrapper(bootstrap_config=config)
try:
yield bootstrapper.bootstrap()
Expand All @@ -299,7 +300,7 @@ def _bootstrapped(config: FastAPIConfig) -> typing.Iterator["fastapi.FastAPI"]:


@contextlib.contextmanager
def _bootstrapped_with_route(config: FastAPIConfig) -> typing.Iterator["fastapi.FastAPI"]:
def _bootstrapped_with_route(config: FastAPIConfig) -> Generator["fastapi.FastAPI"]:
with _bootstrapped(config) as application:

@application.post("/items/{item_id}")
Expand Down
3 changes: 2 additions & 1 deletion tests/test_litestar_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import typing
import warnings
import weakref
from collections.abc import Generator
from unittest.mock import AsyncMock, patch

import litestar
Expand Down Expand Up @@ -307,7 +308,7 @@ def emit(self, record: logging.LogRecord) -> None:


@contextlib.contextmanager
def _recorded_litestar_logs() -> typing.Iterator[list[str]]:
def _recorded_litestar_logs() -> Generator[list[str]]:
"""Record Litestar's rendered log lines.

Enter this inside the TestClient context: Litestar's StructLoggingConfig runs dictConfig at
Expand Down
Loading