Skip to content

Commit 1004155

Browse files
authored
[channels] Use async def instead of a decorator (#15590)
1 parent 08628ce commit 1004155

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

stubs/channels/@tests/stubtest_allowlist.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ channels.auth.UserLazyObject.MultipleObjectsReturned
77
channels.auth.UserLazyObject.NotUpdated
88
channels.auth.UserLazyObject@AnnotatedWith
99

10+
# "is not a function", because it's wrapped in database_sync_to_async,
11+
# which makes it a class instance.
12+
channels.consumer.SyncConsumer.dispatch
13+
1014
# database_sync_to_async is implemented as a class instance but stubbed as a function
1115
# for better type inference when used as decorator/function
1216
channels.db.database_sync_to_async

stubs/channels/channels/consumer.pyi

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ from typing import Any, ClassVar, Protocol, TypedDict, type_check_only
33

44
from asgiref.typing import ASGIReceiveCallable, ASGISendCallable, Scope, WebSocketScope
55
from channels.auth import UserLazyObject
6-
from channels.db import database_sync_to_async
76
from channels.layers import BaseChannelLayer
87
from django.contrib.sessions.backends.base import SessionBase
98
from django.utils.functional import LazyObject
@@ -70,6 +69,5 @@ class SyncConsumer(AsyncConsumer):
7069

7170
# Since we're overriding asynchronous methods with synchronous ones,
7271
# we need to use `# type: ignore[override]` to suppress mypy errors.
73-
@database_sync_to_async
74-
def dispatch(self, message: dict[str, Any]) -> None: ... # type: ignore[override]
72+
async def dispatch(self, message: dict[str, Any]) -> None: ... # type: ignore[override]
7573
def send(self, message: dict[str, Any]) -> None: ... # type: ignore[override]

0 commit comments

Comments
 (0)