Skip to content

Use Sequence instead of List for path param #659

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 3, 2021
Merged
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
6 changes: 3 additions & 3 deletions django-stubs/conf/urls/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Stubs for django.conf.urls (Python 3.5)
from typing import Any, Callable, Dict, List, Optional, overload, Tuple, Union
from typing import Any, Callable, Dict, Optional, overload, Sequence, Tuple, Union

from django.http.response import HttpResponse, HttpResponseBase

Expand All @@ -10,7 +10,7 @@ handler403: Union[str, Callable[..., HttpResponse]] = ...
handler404: Union[str, Callable[..., HttpResponse]] = ...
handler500: Union[str, Callable[..., HttpResponse]] = ...

IncludedURLConf = Tuple[List[Union[URLResolver, URLPattern]], Optional[str], Optional[str]]
IncludedURLConf = Tuple[Sequence[Union[URLResolver, URLPattern]], Optional[str], Optional[str]]

def include(arg: Any, namespace: str = ..., app_name: str = ...) -> IncludedURLConf: ...
@overload
Expand All @@ -21,5 +21,5 @@ def url(
def url(regex: str, view: IncludedURLConf, kwargs: Dict[str, Any] = ..., name: str = ...) -> URLResolver: ...
@overload
def url(
regex: str, view: List[Union[URLResolver, str]], kwargs: Dict[str, Any] = ..., name: str = ...
regex: str, view: Sequence[Union[URLResolver, str]], kwargs: Dict[str, Any] = ..., name: str = ...
) -> URLResolver: ...
8 changes: 4 additions & 4 deletions django-stubs/urls/conf.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from typing import Any, List, Optional, Tuple, overload, Callable, Dict, Union
from typing import Any, Optional, Sequence, Tuple, overload, Callable, Dict, Union

from .resolvers import URLResolver, URLPattern
from ..conf.urls import IncludedURLConf
from ..http.response import HttpResponseBase

def include(
arg: Any, namespace: Optional[str] = ...
) -> Tuple[List[Union[URLResolver, URLPattern]], Optional[str], Optional[str]]: ...
) -> Tuple[Sequence[Union[URLResolver, URLPattern]], Optional[str], Optional[str]]: ...

# path()
@overload
Expand All @@ -17,7 +17,7 @@ def path(
def path(route: str, view: IncludedURLConf, kwargs: Dict[str, Any] = ..., name: str = ...) -> URLResolver: ...
@overload
def path(
route: str, view: List[Union[URLResolver, str]], kwargs: Dict[str, Any] = ..., name: str = ...
route: str, view: Sequence[Union[URLResolver, str]], kwargs: Dict[str, Any] = ..., name: str = ...
) -> URLResolver: ...

# re_path()
Expand All @@ -29,5 +29,5 @@ def re_path(
def re_path(route: str, view: IncludedURLConf, kwargs: Dict[str, Any] = ..., name: str = ...) -> URLResolver: ...
@overload
def re_path(
route: str, view: List[Union[URLResolver, str]], kwargs: Dict[str, Any] = ..., name: str = ...
route: str, view: Sequence[Union[URLResolver, str]], kwargs: Dict[str, Any] = ..., name: str = ...
) -> URLResolver: ...
10 changes: 10 additions & 0 deletions tests/typecheck/urls/test_conf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,13 @@
def include() -> Tuple[List[Union[URLPattern, URLResolver]], None, None]: ...

path('test/', include())


- case: test_path_accepts_pattern_resolver_union_subset
main: |
from typing import List, Tuple
from django.urls import path, URLPattern

def include() -> Tuple[List[URLPattern], None, None]: ...

path('test/', include())