[channels] Use async def instead of a decorator (#15590)

This commit is contained in:
Sebastian Rittau
2026-04-01 15:22:32 +02:00
committed by GitHub
parent 08628cee95
commit 1004155b8e
2 changed files with 5 additions and 3 deletions
@@ -7,6 +7,10 @@ channels.auth.UserLazyObject.MultipleObjectsReturned
channels.auth.UserLazyObject.NotUpdated
channels.auth.UserLazyObject@AnnotatedWith
# "is not a function", because it's wrapped in database_sync_to_async,
# which makes it a class instance.
channels.consumer.SyncConsumer.dispatch
# database_sync_to_async is implemented as a class instance but stubbed as a function
# for better type inference when used as decorator/function
channels.db.database_sync_to_async
+1 -3
View File
@@ -3,7 +3,6 @@ from typing import Any, ClassVar, Protocol, TypedDict, type_check_only
from asgiref.typing import ASGIReceiveCallable, ASGISendCallable, Scope, WebSocketScope
from channels.auth import UserLazyObject
from channels.db import database_sync_to_async
from channels.layers import BaseChannelLayer
from django.contrib.sessions.backends.base import SessionBase
from django.utils.functional import LazyObject
@@ -70,6 +69,5 @@ class SyncConsumer(AsyncConsumer):
# Since we're overriding asynchronous methods with synchronous ones,
# we need to use `# type: ignore[override]` to suppress mypy errors.
@database_sync_to_async
def dispatch(self, message: dict[str, Any]) -> None: ... # type: ignore[override]
async def dispatch(self, message: dict[str, Any]) -> None: ... # type: ignore[override]
def send(self, message: dict[str, Any]) -> None: ... # type: ignore[override]