mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-12 06:51:53 +08:00
Add URLPattern options to django.url.conf since they were missing. (#583)
* Add URLPattern options to django.url.conf since they were missing. * Fix some wording in the contribution guide & fix a reference to Django version 3.0, which has since been replaced by 3.1 as new stable version. * My bad - I was misreading the type hints a bit here. Fix tests. * We need to specify the List[Union[URLResolver, URLPattern]] upfront, since those don't accept List[URLResolver] as argument. * Add test to ensure that path() accepts a mix of URLPatterns & URLResolvers. Co-authored-by: LanDinh <coding+sourcetree@khaleesi.ninja>
This commit is contained in:
@@ -70,11 +70,11 @@ To execute the unit tests, simply run:
|
|||||||
pytest
|
pytest
|
||||||
```
|
```
|
||||||
|
|
||||||
We also test the stubs against the Django's own test suite. This is done in CI but you can also do this locally.
|
We also test the stubs against Django's own test suite. This is done in CI but you can also do this locally.
|
||||||
To execute the script run:
|
To execute the script run:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
python ./scripts/typecheck_tests.py --django_version 3.0
|
python ./scripts/typecheck_tests.py --django_version 3.1
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ handler403: Union[str, Callable[..., HttpResponse]] = ...
|
|||||||
handler404: Union[str, Callable[..., HttpResponse]] = ...
|
handler404: Union[str, Callable[..., HttpResponse]] = ...
|
||||||
handler500: Union[str, Callable[..., HttpResponse]] = ...
|
handler500: Union[str, Callable[..., HttpResponse]] = ...
|
||||||
|
|
||||||
IncludedURLConf = Tuple[List[URLResolver], Optional[str], Optional[str]]
|
IncludedURLConf = Tuple[List[Union[URLResolver, URLPattern]], Optional[str], Optional[str]]
|
||||||
|
|
||||||
def include(arg: Any, namespace: str = ..., app_name: str = ...) -> IncludedURLConf: ...
|
def include(arg: Any, namespace: str = ..., app_name: str = ...) -> IncludedURLConf: ...
|
||||||
@overload
|
@overload
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from django.db.models.base import Model
|
|||||||
from django.db.models.query import QuerySet
|
from django.db.models.query import QuerySet
|
||||||
from django.http.response import HttpResponse
|
from django.http.response import HttpResponse
|
||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
from django.urls.resolvers import URLResolver
|
from django.urls import URLResolver, URLPattern
|
||||||
from django.utils.functional import LazyObject
|
from django.utils.functional import LazyObject
|
||||||
from django.core.checks import CheckMessage
|
from django.core.checks import CheckMessage
|
||||||
|
|
||||||
@@ -67,7 +67,7 @@ class AdminSite:
|
|||||||
def admin_view(self, view: Callable, cacheable: bool = ...) -> Callable: ...
|
def admin_view(self, view: Callable, cacheable: bool = ...) -> Callable: ...
|
||||||
def get_urls(self) -> List[URLResolver]: ...
|
def get_urls(self) -> List[URLResolver]: ...
|
||||||
@property
|
@property
|
||||||
def urls(self) -> Tuple[List[URLResolver], str, str]: ...
|
def urls(self) -> Tuple[List[Union[URLResolver, URLPattern]], str, str]: ...
|
||||||
def each_context(self, request: WSGIRequest) -> Dict[str, Any]: ...
|
def each_context(self, request: WSGIRequest) -> Dict[str, Any]: ...
|
||||||
def password_change(
|
def password_change(
|
||||||
self, request: WSGIRequest, extra_context: Optional[Dict[str, Any]] = ...
|
self, request: WSGIRequest, extra_context: Optional[Dict[str, Any]] = ...
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ from .resolvers import URLResolver, URLPattern
|
|||||||
from ..conf.urls import IncludedURLConf
|
from ..conf.urls import IncludedURLConf
|
||||||
from ..http.response import HttpResponseBase
|
from ..http.response import HttpResponseBase
|
||||||
|
|
||||||
def include(arg: Any, namespace: Optional[str] = ...) -> Tuple[List[URLResolver], Optional[str], Optional[str]]: ...
|
def include(arg: Any, namespace: Optional[str] = ...) -> Tuple[List[Union[URLResolver, URLPattern]], Optional[str], Optional[str]]: ...
|
||||||
|
|
||||||
# path()
|
# path()
|
||||||
@overload
|
@overload
|
||||||
|
|||||||
8
tests/typecheck/urls/test_conf.yml
Normal file
8
tests/typecheck/urls/test_conf.yml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
- case: test_path_accepts_mix_of_pattern_and_resolver_output
|
||||||
|
main: |
|
||||||
|
from typing import List, Tuple, Union
|
||||||
|
from django.urls import path, URLPattern, URLResolver
|
||||||
|
|
||||||
|
def include() -> Tuple[List[Union[URLPattern, URLResolver]], None, None]: ...
|
||||||
|
|
||||||
|
path('test/', include())
|
||||||
Reference in New Issue
Block a user