Skip to content

Commit ae11015

Browse files
restore iterability of ResolverMatch (#38)
Co-authored-by: Anthony Sottile <[email protected]>
1 parent 65d4125 commit ae11015

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

django-stubs/urls/resolvers.pyi

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from collections.abc import Callable, Sequence
1+
from collections.abc import Callable, Iterator, Sequence
22
from re import Pattern
33
from types import ModuleType
44
from typing import Any, TypeAlias, overload
@@ -36,6 +36,8 @@ class ResolverMatch:
3636
extra_kwargs: dict[str, Any] | None = ...,
3737
) -> None: ...
3838
def __getitem__(self, index: int) -> Any: ...
39+
# for tuple unpacking -- python/mypy#2220
40+
def __iter__(self) -> Iterator[Any]: ...
3941

4042
def get_resolver(urlconf: str | None = ...) -> URLResolver: ...
4143
def get_ns_resolver(ns_pattern: str, resolver: URLResolver, converters: tuple) -> URLResolver: ...

scripts/stubtest/allowlist.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,3 +284,7 @@ django.test.selenium.SeleniumTestCase.__init_subclass__
284284

285285
# Django incorrectly uses a signature of `(self, *args, **kwargs)` when it should be `(self)`.
286286
django.forms.renderers.Jinja2DivFormRenderer.__init__
287+
288+
# mypy does not understand __getitem__ unpacking python/mypy#2220
289+
django.urls.ResolverMatch.__iter__
290+
django.urls.resolvers.ResolverMatch.__iter__
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from django.urls.resolvers import ResolverMatch
2+
3+
4+
def f(x: ResolverMatch) -> None:
5+
_func, _args, _kwargs = x # does not error
6+
# would be nice but we can't really get this without tuple specialization
7+
# as `__getitem__` is implemented as `return (..., ...)[...]`
8+
# assert_type(_func, Callable)

0 commit comments

Comments
 (0)