Skip to content
Open
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
5 changes: 3 additions & 2 deletions stubs/channels/channels/routing.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from collections.abc import Collection
from typing import Any, type_check_only

from asgiref.typing import ASGIReceiveCallable, ASGISendCallable, Scope
Expand All @@ -19,9 +20,9 @@ class _ExtendedURLPattern(URLPattern):
callback: _ASGIApplicationProtocol | URLRouter

class URLRouter:
routes: list[_ExtendedURLPattern | URLRouter]
routes: Collection[_ExtendedURLPattern | URLRouter]

def __init__(self, routes: list[_ExtendedURLPattern | URLRouter]) -> None: ...
def __init__(self, routes: Collection[_ExtendedURLPattern | URLRouter]) -> None: ...
Comment on lines +23 to +25
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The typeshed standard for for ... in loops is Iterable. In fact, Collection won't work:

from collections.abc import Container

x: Container[int] = []

for y in x:  # error: "Container[int]" has no attribute "__iter__" (not iterable)
    reveal_type(y)  # note: Revealed type is "Any"

async def __call__(self, scope: Scope, receive: ASGIReceiveCallable, send: ASGISendCallable) -> None: ...

class ChannelNameRouter:
Expand Down
5 changes: 3 additions & 2 deletions stubs/channels/channels/utils.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
from collections.abc import Awaitable, Callable
from collections.abc import Awaitable, Callable, Sequence
from typing import Any, Protocol, type_check_only
from typing_extensions import TypeAlias

from asgiref.typing import ASGIApplication, ASGIReceiveCallable

def name_that_thing(thing: object) -> str: ...
async def await_many_dispatch(
consumer_callables: list[Callable[[], Awaitable[ASGIReceiveCallable]]], dispatch: Callable[[dict[str, Any]], Awaitable[None]]
consumer_callables: Sequence[Callable[[], Awaitable[ASGIReceiveCallable]]],
dispatch: Callable[[dict[str, Any]], Awaitable[None]],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the return value of dispatch is ignored, it can be an arbitrary value and doesn't have to be None:

Suggested change
dispatch: Callable[[dict[str, Any]], Awaitable[None]],
dispatch: Callable[[dict[str, Any]], Awaitable[object]],

) -> None: ...

# Defines a generic ASGI middleware protocol.
Expand Down
10 changes: 8 additions & 2 deletions stubs/channels/channels/worker.pyi
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
from collections.abc import Collection
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above.


from asgiref.server import StatelessServer
from channels.layers import BaseChannelLayer
from channels.utils import _ChannelApplication

class Worker(StatelessServer):
channels: list[str]
channels: Collection[str]
channel_layer: BaseChannelLayer

def __init__(
self, application: _ChannelApplication, channels: list[str], channel_layer: BaseChannelLayer, max_applications: int = 1000
self,
application: _ChannelApplication,
channels: Collection[str],
channel_layer: BaseChannelLayer,
max_applications: int = 1000,
) -> None: ...
async def handle(self) -> None: ...
async def listener(self, channel: str) -> None: ...