Skip to content

Commit

Permalink
use more modern version for types
Browse files Browse the repository at this point in the history
  • Loading branch information
whilenot-dev committed Dec 5, 2024
1 parent f5fd21a commit 9b49172
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions uvicorn/lifespan/on.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import asyncio
import logging
from asyncio import Queue
from typing import Any, Optional, Union, cast
from typing import Any

from uvicorn import Config
from uvicorn._types import (
Expand All @@ -16,13 +16,16 @@
LifespanStartupFailedEvent,
)

LifespanReceiveMessage = Union[LifespanStartupEvent, LifespanShutdownEvent]
LifespanSendMessage = Union[
LifespanStartupFailedEvent,
LifespanShutdownFailedEvent,
LifespanStartupCompleteEvent,
LifespanShutdownCompleteEvent,
]
LifespanReceiveMessage = (
LifespanStartupEvent
| LifespanShutdownEvent
)
LifespanSendMessage = (
LifespanStartupFailedEvent
| LifespanShutdownFailedEvent
| LifespanStartupCompleteEvent
| LifespanShutdownCompleteEvent
)


STATE_TRANSITION_ERROR = "Got invalid state transition on lifespan protocol."
Expand Down Expand Up @@ -80,7 +83,7 @@ async def main(self) -> None:
app = self.config.loaded_app

# inject worker id into app state
uvicorn_worker_id = cast(Optional[int], self.state.get("uvicorn_worker_id"))
uvicorn_worker_id: int | None = self.state.get("uvicorn_worker_id")
if uvicorn_worker_id is not None and hasattr(app.app, "__iter__") and "state" in app.app:
app.app.state.uvicorn_worker_id = uvicorn_worker_id

Expand Down

0 comments on commit 9b49172

Please sign in to comment.