From 25aabe05ce68c69d7e66d5988c23bd63902407ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Tue, 14 Mar 2023 03:19:04 +0100 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=8E=A8=20Fix=20types=20for=20lifespan?= =?UTF-8?q?,=20upgrade=20Starlette=20to=200.26.1=20(#9245)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fastapi/applications.py | 7 +++++-- fastapi/routing.py | 4 +++- pyproject.toml | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/fastapi/applications.py b/fastapi/applications.py index 330525936..8b3a74d3c 100644 --- a/fastapi/applications.py +++ b/fastapi/applications.py @@ -9,6 +9,7 @@ from typing import ( Optional, Sequence, Type, + TypeVar, Union, ) @@ -43,10 +44,12 @@ from starlette.responses import HTMLResponse, JSONResponse, Response from starlette.routing import BaseRoute from starlette.types import ASGIApp, Lifespan, Receive, Scope, Send +AppType = TypeVar("AppType", bound="FastAPI") + class FastAPI(Starlette): def __init__( - self, + self: AppType, *, debug: bool = False, routes: Optional[List[BaseRoute]] = None, @@ -71,7 +74,7 @@ class FastAPI(Starlette): ] = None, on_startup: Optional[Sequence[Callable[[], Any]]] = None, on_shutdown: Optional[Sequence[Callable[[], Any]]] = None, - lifespan: Optional[Lifespan] = None, + lifespan: Optional[Lifespan[AppType]] = None, terms_of_service: Optional[str] = None, contact: Optional[Dict[str, Union[str, Any]]] = None, license_info: Optional[Dict[str, Union[str, Any]]] = None, diff --git a/fastapi/routing.py b/fastapi/routing.py index c227ea6ba..06c71bffa 100644 --- a/fastapi/routing.py +++ b/fastapi/routing.py @@ -492,7 +492,9 @@ class APIRouter(routing.Router): route_class: Type[APIRoute] = APIRoute, on_startup: Optional[Sequence[Callable[[], Any]]] = None, on_shutdown: Optional[Sequence[Callable[[], Any]]] = None, - lifespan: Optional[Lifespan] = None, + # the generic to Lifespan[AppType] is the type of the top level application + # which the router cannot know statically, so we use typing.Any + lifespan: Optional[Lifespan[Any]] = None, deprecated: Optional[bool] = None, include_in_schema: bool = True, generate_unique_id_function: Callable[[APIRoute], str] = Default( diff --git a/pyproject.toml b/pyproject.toml index 2ae582722..b8d006359 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -41,7 +41,7 @@ classifiers = [ "Topic :: Internet :: WWW/HTTP", ] dependencies = [ - "starlette>=0.26.0,<0.27.0", + "starlette>=0.26.1,<0.27.0", "pydantic >=1.6.2,!=1.7,!=1.7.1,!=1.7.2,!=1.7.3,!=1.8,!=1.8.1,<2.0.0", ] dynamic = ["version"] From 7b7e86a3078e71442fda69a1e487d26b90760747 Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 14 Mar 2023 02:19:50 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9D=20Update=20release=20notes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 192fa7a6b..261e2f697 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -2,6 +2,7 @@ ## Latest Changes +* 🎨 Fix types for lifespan, upgrade Starlette to 0.26.1. PR [#9245](https://github.com/tiangolo/fastapi/pull/9245) by [@tiangolo](https://github.com/tiangolo). ## 0.94.0 From ef176c663195489b44030bfe1fb94a317762c8d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Tue, 14 Mar 2023 03:27:11 +0100 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=94=96=20Release=20version=200.94.1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/en/docs/release-notes.md | 5 +++++ fastapi/__init__.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/docs/en/docs/release-notes.md b/docs/en/docs/release-notes.md index 261e2f697..118ee1dc7 100644 --- a/docs/en/docs/release-notes.md +++ b/docs/en/docs/release-notes.md @@ -2,6 +2,11 @@ ## Latest Changes + +## 0.94.1 + +### Fixes + * 🎨 Fix types for lifespan, upgrade Starlette to 0.26.1. PR [#9245](https://github.com/tiangolo/fastapi/pull/9245) by [@tiangolo](https://github.com/tiangolo). ## 0.94.0 diff --git a/fastapi/__init__.py b/fastapi/__init__.py index e71b648f9..05da7b759 100644 --- a/fastapi/__init__.py +++ b/fastapi/__init__.py @@ -1,6 +1,6 @@ """FastAPI framework, high performance, easy to learn, fast to code, ready for production""" -__version__ = "0.94.0" +__version__ = "0.94.1" from starlette import status as status