Skip to content
Open
Changes from 1 commit
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
Next Next commit
[channels] Make URLRouter.routes a Collection
`list` is invariant, which made this type inconvenient in practice.
Each of the routes is either a pattern or another router.
  • Loading branch information
cjwatson committed Nov 25, 2025
commit 0d165cf053e2d640c71f73953fdb81de265478dd
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