mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-10 22:11:54 +08:00
Check arguments to django.urls.{path,re_path} functions (#464)
These functions were added in Django 2.0, but the stubs have been
incomplete since commit 9a68263257
The implementation is almost identical to `url()` from
`conf/urls/__init__.pyi`
This commit is contained in:
@@ -1,8 +1,31 @@
|
||||
from typing import Any, List, Optional, Tuple
|
||||
from typing import Any, List, Optional, Tuple, overload, Callable, Dict, Union
|
||||
|
||||
from .resolvers import URLResolver
|
||||
from .resolvers import URLResolver, URLPattern
|
||||
from ..conf.urls import IncludedURLConf
|
||||
from ..http.response import HttpResponseBase
|
||||
|
||||
def include(arg: Any, namespace: Optional[str] = ...) -> Tuple[List[URLResolver], Optional[str], Optional[str]]: ...
|
||||
|
||||
path: Any
|
||||
re_path: Any
|
||||
# path()
|
||||
@overload
|
||||
def path(
|
||||
route: str, view: Callable[..., HttpResponseBase], kwargs: Dict[str, Any] = ..., name: str = ...
|
||||
) -> URLPattern: ...
|
||||
@overload
|
||||
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 = ...
|
||||
) -> URLResolver: ...
|
||||
|
||||
# re_path()
|
||||
@overload
|
||||
def re_path(
|
||||
route: str, view: Callable[..., HttpResponseBase], kwargs: Dict[str, Any] = ..., name: str = ...
|
||||
) -> URLPattern: ...
|
||||
@overload
|
||||
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 = ...
|
||||
) -> URLResolver: ...
|
||||
|
||||
@@ -451,9 +451,11 @@ IGNORED_ERRORS = {
|
||||
'urlpatterns': [
|
||||
'"object" not callable',
|
||||
'"None" not callable',
|
||||
'Argument 2 to "path" has incompatible type "Callable[[Any], None]"',
|
||||
'Incompatible return value type (got "None", expected "HttpResponseBase")',
|
||||
],
|
||||
'urlpatterns_reverse': [
|
||||
'List or tuple expected as variable arguments',
|
||||
'No overload variant of "path" matches argument types "str", "None"',
|
||||
'No overload variant of "zip" matches argument types "Any", "object"',
|
||||
'Argument 1 to "get_callable" has incompatible type "int"'
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user